Build an RPG Character - Build an RPG Character

Tell us what’s happening:

Code returns “all stats should be integers” but why?

Your code so far

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 = {"sta":strength, 'inl':intelligence, "cha":charisma}
    for stat in stats.values():
        if stat != int:
            return "All stats should be intergers"
    if stat < 1:
        return "All stats should be no less than 1"
    if stat > 4:
        return "All stats should be no more than 4"
    if sum(stat.value()) != 7:
        return "The character should start with 7 points"
    character_string = name
    for key, stat in stats.items():
        character_string += f'\n{key} {full_dot*stat}{empty_dot*(10-stat)}'
    return character_string

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Build an RPG Character - Build an RPG Character

Welcome to the forum @jakethomas228

Before the if statement print stat and int.

Happy coding

Its probably due to that its printing STA, INT, and CHA, as well as the numerical value for them?

you have stat != int in the condition tho, not isinstance

printing is for debugging, not to fix the function, you see what is printed and then fix the funtion based on that

I understand. I truly dont get what is the problem with this. It passes the test. The values are int.

now I see that you don’t have stat != int anymore, but to allow to test you code please post your code, not a screenshot

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

what do you think is the value of stat outside the loop?

Please post code not screenshots

apologies ill delete it

Don’t need to delete anything, just post text code in the future, so we can test it or copy/paste sections if needed.

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 = {"STA":strength, "INL":intelligence, "CHA":charisma}

for stat in stats.values():

    print(stats)

    print(stats.values())

    if not isinstance(stats,int):

        return "All stats should be integers"

if stat < 1:

    return "All stats should be no less than 1"

if stat > 4:

    return "All stats should be no more than 4"

if sum(stat.value()) != 7:

    return "The character should start with 7 points"

character_string = name

for key, stat in stats.items():

    character_string += f'\\n{key} {full_dot\*stat}{empty_dot\*(10-stat)}'

return character_string

print(create_character(‘ren’,4, 2, 1))

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

The code prints that all values should be integers.

Is that good or bad? Why? Did you test it? Explain more please

well, i dont believe it should happen as the stat values are all integers
also running the test, step 7 is working correctly, but step 8 is not.

what is it that you are testing here?

if the stats are not integers, print “all stats must be integers?

what is stats?

it seems a dictionary to me