def create_character(name, strength, intelligence, charisma):
if not isinstance(name, str):
return ‘The character name should be a string’
if name == “”:
return ‘The character should have a name’
if len(name)>10:
return ‘The character name is too long’
if " " in name:
return ‘The character name should not contain spaces’
if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
return ‘All stats should be integers’
if strength < 1 or intelligence < 1 or charisma < 1:
return ‘All stats should be no less than 1’
if strength > 4 or intelligence > 4 or charisma > 4:
return ‘All stats should be no more than 4’
if strength + intelligence + charisma != 7:
return ‘The character should start with 7 points’
I do NOT understand why my code isn’t working. I have tried so many different ways to make this work. I have been all over this site regarding this particular lab to try and figure it out from other people and I can’t get it to work. 18 and 19 refuse to run for me.
I understand the method people are going about on here when it comes to not giving the answer straight away and trying to teach, but none of that has helped me when looking through. Can someone please give me some sort of direction that will actually help me through this?
There are two ways you can format your code to make it easier to read and test:
After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)
Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.
To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
if not isinstance(name, str):
return 'The character name should be a string'
if name == "":
return 'The character should have a name'
if len(name)>10:
return 'The character name is too long'
if " " in name:
return 'The character name should not contain spaces'
if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
return 'All stats should be integers'
if strength < 1 or intelligence < 1 or charisma < 1:
return 'All stats should be no less than 1'
if strength > 4 or intelligence > 4 or charisma > 4:
return 'All stats should be no more than 4'
if strength + intelligence + charisma != 7:
return 'The character should start with 7 points'
final_character = f'{name}'
f'STR,{strength * full_dot + empty_dot * (10 - strength)}'
f'INT,{intelligence * full_dot + empty_dot * (10 - intelligence)}'
f'CHA,{charisma * full_dot + empty_dot * (10 - charisma)}'
return(final_character)
print(create_character('ren', 4, 2, 1))
This is the updated code. It only prints ren for me in the console. The tips didn’t help me either. Can anyone give me the answer for this?