Build an RPG Character - Build an RPG Character

I don’t know. How would I test that?

Test a call where all the stats are integers

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

It returns “all stats should be integers". If I rewrite if not isinstance(stats, int): with a bunch of or’s it asks to define it; how should I do that?

show the code instead of describing it

You don’t have to use or (but you HAVE already written lines like that)

You cannot pass a list to isinstance()

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
#name validations
    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"
#stat validations
    if not isinstance(strength or intelligence or charisma, int):
        return "All stats should be integers"
    if strength < 1 or intelligence < 1 or charisma < 1:
        return "All stats should be no less than 1"
    if strength > 4 or intelligence > 4 or charisma > 4:
        return "All stats should be no more than 4"
    if strength + intelligence + charisma != 7:
        return "The character should start with 7 points"
    
    def make_bar(value):
        return full_dot * value + empty_dot * (10 - value)
    result = f"""{name}
    STR {make_bar(strengeth)}
    INT {make_bar(intelligence)}
    CHA {make_bar(charisma)}"""
    return result

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

We see you have posted some code but did you have a question?

if not isinstance(strength or intelligence or charisma, int):

That line isn’t passing any of the tests. If I write each stat individually it’s giving me name error. I think the main issue is that the stats aren’t “defined", how should I define the stat?

what do you think this is doing?

I think you should do a web search for how to use isinstance. This is not the correct syntax.

1 Like

I thought it was testing each stat if it was an integer or not, but I’m assuming it’s wrong

if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int): This fixed the earlier issues. Now just test 11 and 12 won’t work.

 return (

        f'{name}\n'

        f'STR {make_bar(strength)}\n'

        f'INT {make_bar(intelligence)}\n'

        f'CHA {make_bar(charisma)}\n')




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

Im using this and it’s causing no erorrs but it prints

ren
STR ●●●●○○○○○○
INT ●●○○○○○○○○
CHA ●○○○○○○○○○

So I’m confused, why is it not correct?

Try using repr() to compare the strings

print(repr(create_character('ren', 4, 2, 1)))
  1. create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.

That worked but the test still isn’t “correct”

    • Failed:11. create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.

    • Failed:12. When create_character is called with valid values it should output the character stats as required.

(for reference to the tests)

you should use repr inside print to compare your output, do not use repr inside create_character

if you don’t see the difference share your output with us and we can help

Compare your output with the output the test shows.

Share it here if you cannot see any differences.

repr(print(create_character('ren', 4, 2, 1))) returns ren
STR ●●●●○○○○○○
INT ●●○○○○○○○○
CHA ●○○○○○○○○○

same with print(repr(create_character('ren', 4, 2, 1)))

no clue what the thing on top is, but it won’t copy and paste

oh and here’s the whole code

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
#name validations
    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"
#stat validations
    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
        return "All stats should be integers"
    if strength < 1 or intelligence < 1 or charisma < 1:
        return "All stats should be no less than 1"
    if strength > 4 or intelligence > 4 or charisma > 4:
        return "All stats should be no more than 4"
    if strength + intelligence + charisma != 7:
        return "The character should start with 7 points"
    
    def make_bar(value):
        return full_dot * value + empty_dot * (10 - value)

    return (

        f'{name}\n'

        f'STR {make_bar(strength)}\n'

        f'INT {make_bar(intelligence)}\n'

        f'CHA {make_bar(charisma)}\n')

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

Did you compare your output with what the test says the output should be?

Every character? (especially the last character)

compare, notice the differences

wow that was a silly mistake, I solved it, just an extra \n