Tell us what’s happening:
Hi, I’m failing tests 9 & 10:
9. create_character(“ren”, 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
10. When create_character is called with valid values it should output the character stats as required.
I have tested every piece of implementation logic and they have succeeded. Output looks spot on - same length, spacing and newlines.
Can anyone give me a hint? Thanks.
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
# The character name should be validated:-----------------
# If the character name is not a string, the function should return The character name should be a string.
if not isinstance(name, str):
return 'The character name should be a string'
# If the character name is longer than 10 characters, the function should return The character name is too long.
if len(name) > 10:
return 'The character name is too long'
# If the character name contains spaces, the function should return The character name should not contain spaces.
if ' ' in name:
return 'The character name should not contain spaces'
# The stats should also be validated: ---------------------
# If one or more stats are not integers, the function should return All stats should be integers.
stats = {'STA':strength, 'INT':intelligence, 'CHA':charisma}
for stat in stats.values():
if not isinstance(stat, int):
return 'All stats should be integers'
# If one or more stats are less than 1, the function should return All stats should be no less than 1.
for stat in stats.values():
if stat < 1:
return 'All stats should be no less than 1'
# If one or more stats are more than 4, the function should return All stats should be no more than 4.
for stat in stats.values():
if stat > 4:
return 'All stats should be no more than 4'
# If the sum of all stats is different than 7, the function should return The character should start with 7 points.
if sum(stats.values()) != 7:
return 'The character should start with 7 points'
# If all values pass the verification, the function should return a string with four lines: ----------------------------
# the first line should contain the character name
character_string = name
# lines 2-4 should start with the stat abbreviation, STR, INT or CHA (in this order), then a space, and then a number of full dots (●) equal to the value of the stat, and a number of empty dots (○) to reach 10. Example: if the value of strength is 3 there must be 3 full dots followed by 7 empty dots. The dots are given in the editor.
for key, stat in stats.items():
character_string += f'\n{key} {full_dot*stat}{empty_dot*(10-stat)}'
return character_string
# ============ TESTS =========================
print(create_character("ren", 4, 2, 1))
test_str = 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'
print(len(test_str))
print(f"{test_str}")
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build an RPG character - Build an RPG Character
https://www.freecodecamp.org/learn/full-stack-developer/lab-rpg-character/build-an-rpg-character


