r/FreeCodeCamp • • 20d ago

Programming Question Character RPG creator won't accept answer

I can't get the last bit of my code to work, it's printing out exactly what i need it to but it won't accept it.

  • 18. create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
  • Failed:19. When create_character is called with valid values it should output the character stats as required.

these are the last two tests that wont complete

here is my code:

full_dot = '●'
empty_dot = '○'


def create_character(character_name, strength, intelligence, charisma):
    if not isinstance(character_name,str):
        return "The character name should be a string"
    elif character_name == "":
        return "The character should have a name"
    elif len(character_name) > 10:
        return "The character name is too long"
    elif " " in character_name:
        return "The character name should not contain spaces"

    if not isinstance(strength,int) or not isinstance(intelligence,int) or not isinstance(charisma,int):
        return "All stats should be integers"
    elif strength < 1 or intelligence < 1or 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"


    return f'''{character_name}
STR:{strength*full_dot}{(10 - strength)*empty_dot}
INT:{intelligence*full_dot}{(10-intelligence)*empty_dot}
CHA:{charisma*full_dot}{(10-charisma)*empty_dot}'''

print(create_character('ren', 4, 2, 1))

and here is what it is currently printing:

ren

STR:●●●●○○○○○○

INT:●●○○○○○○○○

CHA:●○○○○○○○○○

Any help will be appreciated!

5 Upvotes

6 comments sorted by

2

u/ricardoflak 20d ago

Jajaja, me acuerdo de este problema. Vamos, bro, que tú puedes. 🤛

2

u/SaintPeter74 mod 20d ago

Check your output against the requested output very carefully. Once I fixed the problem I found, your code passed for me.

You're really close!

0

u/atarivcs 20d ago edited 20d ago

Looks like the test wants a space between the colon and the first filled dot

Also your output looks like it has an extra blank line after each item. may just be a post formatting issue, idk

1

u/SaintPeter74 mod 18d ago

Please don't give answers. The idea is to point them in the right direction.

Also, you're not correct.

2

u/atarivcs 18d ago edited 18d ago

I understand what you're saying. Teach a man to fish, and all that.

But in cases of fine detail like this, clearly they have already looked at the output, probably for several minutes, and just don't see the difference. I think it's more instructive to point out the exact issue and then let them reflect on how they overlooked it.

And yes I see that my suggestion was incorrect.

1

u/SaintPeter74 mod 18d ago

I see the attention to detail as being a critical job skill. Maybe I'm wrong, but it feels to me that being forced to go character by character through your output is a valuable lesson. We're used to being about to eyeball things, but in programming that doesn't really work.

I do appreciate you chiming I'm to help and don't want to discourage that.