Build an RPG character - Build an RPG Character

Tell us what’s happening:

can anyone help me how to solve this? thank you!!!

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(name, strength, intelligence, charisma):
    # Name validation
    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 "" in name:
        return 'The character name should not contain spaces'

    # Stats validation
    stats = [strength, intelligence, charisma]
    for stat in stats:
        if not isinstance(stat, int):
            return 'All stats should be integers'
        if not(1 <= stat <= 4):
            return 'All stats should be no less than 1 and no more than 4'
    if sum(stats) != 7:
        return 'The character should start with 7 points'

Your browser information:

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

Challenge Information:

Build an RPG character - Build an RPG Character

What isn’t working?

What have you tried to fix it?

How did you get stuck?

i only copied the #STATS VALIDATION from google and freecodecamp is not accepting the coding

Ok, I would delete the code you copied and try to write the code yourself.

i have already tried different code but i can not really solve it. i first tried doing this:

     if not isinstance(strength, intelligence, charisma, int):
       return 'All stats should be integers'

Hmm did previous examples of isinstance take multiple different variables at the same time? I don’t think they did.

What about using a logical and?

I still cannot solve it, I tried ‘and’ and ‘or’ operators.

I think the problem is the third if statement for name. you’re supposed to check for space, but it’s an empty string which is considered to exist in every string and it keeps stopping there before ever reaching the integer check. Hope it helps :smiley:

this part is making me unmotivated and making me to not continue learning software engineering. :face_holding_back_tears:

i do not have problem with NAME IF STATEMENTS. My concern now is the step 5 or the IF STATEMENTS FOR STATS.

You do… That’s what’s stopping you from reaching the stats check at all… you’re not checking for space but an empty string which is always true and returns prematurely. Try printing the function and you’ll see… You passed Step 4 somehow, but IF ONLY you made that small change, you’d pass Step 5… Step 6 and 7 is failing because you ignored the instructions and combined the statements on your own. You gotta follow it exactly as told or it’d fail. If you’re still not convinced, I can’t help further. All the best tho.

freeCodeCamp accepted my step 1 - 4 coding. Only the step 5 - 10 that they do not accept. I cannot move on from this challenge. I’m stuck here for hours already. Help me please.

For the last time, just try printing the function… and do what I hinted :sweat_smile: Your original code was okay. Only needed to fix those things.

The problem is that you are copying code you find and not really working to understand what you’re doing. You may want to go back to previous lessons and make sure you really understand the material.

If you have a question about something you don’t understand, you should ask in the forum.

Of course, everyone working on this is just a beginner.

You way of learning or your way of easily passing the labs?

You should never be copying code and putting it in the editor here. You should definitely be searching for resources on how to use a particular function, or how to do something.

“python how to check type”
“python type()”
“python how to loop”

Read how to use the tools, then implement it yourself.

It’s not accepting code you copied, but why can’t you figure it out? It’s because you haven’t been learning.

To actually solve this take this advice:

You need to print the function to see the output

print(create_character("test a long name with spaces", 0, 2, 3))

Use print()

Use print() in your code to check on variables and test statements. You have no print statements at all in your code so you are totally blind to anything that’s happening

Does this work??

I don’t know, try printing it!

print(not isinstance(strength, intelligence, charisma, int))

Does it give the output you expected or an error? What’s the error say?

Do you understand how to print the result of the function?

Did you try this? I’ve shared this with you already

" but there is no print function in the instruction they will only accept what is asked"

It doesn’t matter. You need to use print() to do tests and maybe write all sorts of code that are just small tests to see the output.

If you need to remove them later before submitting the finished program, then you can.

It’s this line “ if “” in name:
return ‘The character name should not contain spaces’“. Empty spaces are found in all strings so that it will always be true. Swap "" for " " and your validation will behave.

“Chris” is a string without a space.

Please read the instructions of the lab.

If the character name contains spaces, the function should return The character name should not contain spaces.

‘““: This represents the empty string

“ “: this represents the space (an ASCII character)

Please read the instructions of the lab; it is asking to check for spaces, not empty strings. Every string as an empty string.

““ is in “Chris“. ““ is in “ “.