Build an RPG character - Build an RPG Character

Tell us what’s happening:

i nested all my conditions to make sure the last return only will be made if all conditions prior are satisfied. the test wont pass further than Test 3, returning “The character name is too long”

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 len(name) > 10:
            return "The character name is too long"
            if isinstance(name.find(" "), int):
                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"
                    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 not strength + intelligence + charisma == 7:
                                return "The character should start with 7 points"
                                return name + "\nSTR " +  "●" * strength + "○" * (10 - strength) + "\nINT " + "●" * intelligence + "○" * (10 - intelligence) + "\nCHA " + "●" * charisma + "○" * (10 - charisma)


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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

Remember that Python indentation to group the code that goes together. This means that ie. in:

    if not isinstance(name, str):
        return "The character name should be a string"
        if len(name) > 10:
            (...)

The second if could only be executed if condition in the first if would be evaluated to True. However, since there’s return before it, it effectively is never executed.

1 Like

if executing return forces an escape out of the block, then how do i make sure the last return is only run if the previous conditions are satisfied? should i list all returns at the bottom or maybe keep a counter that increases in every loop once?

you need to not put each if statement inside the previous if statement

make sure you understand what indentation means in python

1 Like