Build an RPG character - Lab

Tell us what’s happening:

Hello,

I cannot get passed step 6 and above. And the console keeps printing “All stats should be integers” despite my stats all being integer when I call the function. I don’t understand.

I have been struggling for over a week on this overall exercice. I had to finish the next chapter (loops and sequences) to have the necessary knowledge to do the loops part. I think I’m nearly there but I don’t understand why I’m stuck T_T

Thanks

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(character_name, strenght, intelligence, charisma):
   
    if not isinstance(character_name, str):
        return "The character name should be a string";
    if len(character_name) > 10:
        return "The character name is too long";
    if ' ' in character_name:
        return "The character name should not contain spaces";
    else:
        pass;

    stats = {'STR': strenght, 'INT': intelligence, 'CHA': charisma};
    stat = list(stats.values())

    for stat in stats:
        if not isinstance(stat, 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(stats.values) != 7:
            return "The character should start with 7 points";
        else:
            pass
    
    return character_name
    for key in stats:
        character_stat_visual = f"{key} {full_dot * stat}{empty_dot * 10 - stat}\n";
        return character_stat_visual


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






Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0

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

Hi @Loup

print(create_character("ren", 4, 2, 1)) # All stats should be integers

The first argument is a string, the rest are integers.

The function is producing an incorrect response.

Review how you are checking for an integer.

Happy coding

I finally did it. It was very hard and not very clear for me. I got some help to crack it because otherwise I was not gotta take this one alone.

My error came from using a dictionary and dividing some statements that can be done more condense.

Good luck to anyone else going through it :flexed_biceps:

1 Like

your issue was a return statement too early, remember that a return statement will stop the execution of the function

2 Likes

I have the same problem in no.5 always to differentiate between int and str, can I ask how you did that part?

It’s best to just open a new thread for your question

1 Like