def create_character(name, strength, intelligence, charisma):
.
.
.
.
if not (isinstance (strength, int) and isinstance (intelligence, int) and isinstance(charisma, int)):
return ‘All stats should be integers’
I am stuck on step 7 and cannot get past it, which tells me to return this message if the second, third, or fourth argument is not an integer. Can someone help me understand why I am stuck here or what I should do? It could potentially help me with step 8, too
Your code so far
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 len(name) > 10:
return 'The character name is too long'
if len(name) == 0:
return 'The character should have a name'
if name.find(' ') < len(name):
return 'The character name should not contain spaces'
if not (isinstance (strength, int) and (intelligence, int) and isinstance(charisma, int)):
return 'All stats should be integers'
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Ok i fixed it. Basically had to change the condition for having a space in name
The updated code for that is “if ‘ ‘ in name: return ‘The character name should not contain spaces‘”
However, I am not sure what step 12 is asking. “print (create_character(‘John’, 3, 3, 1))“ This gives me the correct output but does not help what is wrong.
Should I make changes to this condition:
if ((strength + intelligence + charisma) != 7):
return 'The character should start with 7 points'
I tried changing the condition to if the sum < 7 but it fails with the condition if it is not equal to 7 (step 10)
def create_character(name, strength, intelligence, charisma):
if not(isinstance(name, str)):
return 'The character name should be a string'
if len(name) > 10:
return 'The character name is too long'
if len(name) == 0:
return 'The character should have a name'
if ' ' in name:
return 'The character name should not contain spaces'
if not (isinstance (strength, int) and isinstance (intelligence, int) and 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'
else:
return ('ren\\nSTR ' + full_dot \* strength + empty_dot \* (10-strength) + '\\nINT ' + full_dot \* intelligence + empty_dot \* (10-intelligence) + '\\nCHA ' + full_dot \* charisma + empty_dot \* (10-charisma))
print (create_character('John', 3, 3, 1))
I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add the backticks.
def create_character(name, strength, intelligence, charisma):
if not(isinstance(name, str)):
return 'The character name should be a string'
if len(name) > 10:
return 'The character name is too long'
if len(name) == 0:
return 'The character should have a name'
if ' ' in name:
return 'The character name should not contain spaces'
if not (isinstance (strength, int) and isinstance (intelligence, int) and 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'
else:
return ('ren\nSTR ' + full_dot * strength + empty_dot * (10-strength) + '\nINT ' + full_dot * intelligence + empty_dot * (10-intelligence) + '\nCHA ' + full_dot * charisma + empty_dot * (10-charisma))
print (create_character('John', 3, 3, 1))
I have tried to do that here and this is the best my laptop is allowing (or on my browser for now). Can you let me know how should I change my condition for sum of stats to be >= 7? I tried to do < 7 as the condition but it seems to reject it for some reason