Needing help with understanding what I am doing wrong here.
I have a few errors that I am getting in the console that I don’t know how to fix.
5. The create_character function should not say that the character is too long when it's not longer than 10 characters.
create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
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'
stats = [strength, intelligence, charisma]
if not all(isinstance(stat, int) for stat in stats):
return 'All stats should be integers'
if not all(stat >= 1 for stat in stats):
return 'All stats should be no less than 1'
if not all(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'
stat_names = ["STR", "INT", "CHA"]
lines = [name] # first line is the character name
for stat_name, value in zip(stat_names, stats):
# full dots = stat value, empty dots = remaining to 10
line = f"{stat_name} {'●'*value}{'○'*(10-value)}"
lines.append(line)
return(create_character('ren', 4, 2, 1))
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'
stats = [strength, intelligence, charisma]
if not all(isinstance(stat, int) for stat in stats):
return 'All stats should be integers'
if not all(stat >= 1 for stat in stats):
return 'All stats should be no less than 1'
if not all(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'
stat_names = ["STR", "INT", "CHA"]
lines = [name] # first line is the character name
for stat_name, value in zip(stat_names, stats):
# full dots = stat value, empty dots = remaining to 10
line = f"{stat_name} {'●'*value}{'○'*(10-value)}"
lines.append(line)
#return(create_character('ren', 4, 2, 1))
print(create_character("name", 3, 3, 1))
With the print at the end added. I was able to remove the first error I was getting.
But still not understanding how to get the return to work.
create_character(‘ren’, 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
The return I had commented out at the end of the def.
When I remove the comment. I do not get anything to show in the console.
But I get the same errors.
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'
stats = [strength, intelligence, charisma]
if not all(isinstance(stat, int) for stat in stats):
return 'All stats should be integers'
if not all(stat >= 1 for stat in stats):
return 'All stats should be no less than 1'
if not all(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'
stat_names = ["STR", "INT", "CHA"]
lines = [name] # first line is the character name
for stat_name, value in zip(stat_names, stats):
# full dots = stat value, empty dots = remaining to 10
line = f"{stat_name}{'●'*value}{'○'*(10-value)}"
lines.append(line)
return(create_character('ren', 4, 2, 1))
// running tests
5. The create_character function should not say that the character is too long when it's not longer than 10 characters.
11. create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
12. When create_character is called with valid values it should output the character stats as required.
// tests completed
So, when the instructions are saying. “Here’s the string that should be returned by create_character('ren', 4, 2, 1):” It doesn’t mean to actually use the return as that?
But the print will give me a None. Then the message. “11. create_character(‘ren’, 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.”