The output in the terminal is correct but the instruction number 10, 12 and 14 is accepting. Is my solution for the if statements not correct?
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name,strength, intelligence, charisma):
total_stats = strength + intelligence + charisma
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 and intelligence and charisma), int):
return "All stats should be integers"
elif (strength and intelligence and charisma) < 1:
return "All stats should be no less than 1"
elif (strength and intelligence and charisma) > 4:
return "All stats should be no more than 4"
elif total_stats != 7:
return "The character should start with 7 points"
else:
strength_stats = (full_dot * strength) + (empty_dot * (10 - strength))
intelligence_stats = (full_dot * intelligence) + (empty_dot * (10 - intelligence))
charisma_stats = (full_dot * charisma) + (empty_dot * (10 - charisma))
character_info = f"{name}\nSTR {strength_stats}\nINT {intelligence_stats}\nCHA {charisma_stats}"
return character_info
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/149.0.0.0 Safari/537.36
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: