Tell us what’s happening:
Steps 11 and 12 aren’t passing the test, but it is working in the terminal…what am I missing?
11: 11. create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
12:12. When create_character is called with valid values it should output the character stats as required.
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
stats=[strength, intelligence, charisma]
if not isinstance(name,str):
return "The character name should be a string"
if not all(isinstance (stat, int)for stat in stats):
return "All stats should be integers"
#Stats
if any(stat < 1 for stat in stats):
return "All stats should be no less than 1"
if any (stat > 4 for stat in stats):
return "All stats should be no more than 4"
if sum (stats) !=7:
return "The character should start with 7 points"
#Name
if not 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"
#Test output
dots=[stat*full_dot + (10 - stat)*empty_dot for stat in stats]
return (
f"{name}"
f"\nSTR{dots[0]}"
f"\nINT{dots[1]}"
f"\nCHA{dots[2]}"
)
print(create_character('ren',4,2,1))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15
Challenge Information:
Build an RPG Character - Build an RPG Character
