i dont know what is the broplem i but the same stats the he told me to but in the user story
Your code so far
def create_character(name, strength, intelligence, charisma):
full_dot = '●'
empty_dot = '○'
if not isinstance(name, str):
return 'The character name should be a string'
elif name == '':
return 'The character should have a name'
elif len(name) > 10:
return 'The character name is too long'
elif ' ' in name :
return 'The character name should not contain spaces'
elif not isinstance(strength, int):
return 'All stats should be integers'
elif not isinstance(intelligence, int):
return 'All stats should be integers'
elif not isinstance(charisma, int):
return 'All stats should be integers'
elif strength < 1 or intelligence <1 or charisma < 1:
return 'All stats should be no less than 1'
elif strength > 4 or intelligence > 4 or charisma > 4:
return 'All stats should be no more than 4'
elif strength + intelligence + charisma != 7:
return 'The character should start with 7 points'
else :
return 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'
print(create_character('ren', 4, 2, 1))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
You are hard coding your return based on specific expected values.
That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?
Here’s an example: print(create_character('giraffe', 3, 1, 3))
To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: Hard-coding For Beginners
Let us know if you have a question about how to make your code more flexible.
Build your return string using the parameters passed to the function. That way what you return string will always reflect the arguments passed to the function call.
hay i did what you said with some help from other people code and i can but any name and numbers it will print it on the terminal but it still tell me that (create_character(‘ren’, 4, 2, 1)) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○
This is my updated code. If I change it to create_character(‘hassan’, 3 ,1 ,3), it will print the stats and the name at the terminal
Your code so far
def create_character(name, STR, INT, CHA):
full_dot = '●'
empty_dot = '○'
if not isinstance(name, str):
return 'The character name should be a string'
elif name == '':
return 'The character should have a name'
elif len(name) > 10:
return 'The character name is too long'
elif ' ' in name :
return 'The character name should not contain spaces'
elif not isinstance(STR, int):
return 'All stats should be integers'
elif not isinstance(INT, int):
return 'All stats should be integers'
elif not isinstance(CHA, int):
return 'All stats should be integers'
elif STR < 1 or INT <1 or CHA < 1:
return 'All stats should be no less than 1'
elif STR > 4 or INT > 4 or CHA > 4:
return 'All stats should be no more than 4'
elif STR + INT + CHA != 7:
return 'The character should start with 7 points'
else :
return f'{name} \nSTR{full_dot*STR}{empty_dot*(10-STR)}\nINT{full_dot*INT}{empty_dot*(10-INT)}\nCHA{full_dot*CHA}{empty_dot*(10-CHA)}'
print(create_character('ren', 4, 2, 1))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36