Build an RPG Character - test 8 and following

Tell us what’s happening:

I have the correct output, but test fail beginning with no 8, which looks correct to me.

Your code so far

full_dot = '●'
empty_dot = '○'
def create_character(cname, stren, intel, chari):
    if not isinstance(cname, str):
        return("The character name should be a string")
    if cname == "":
        return("The character should have a name")
    if len(cname) > 10:
        return("The character name is too long")
    if " " in cname :
        return("The character name should not contain spaces")
    if (isinstance(stren,int) or isinstance(intel,int) or isinstance(chari,int)):
        return("All stats should be integers")
    stren = int(stren)
    intel = int(intel)
    chari = int(chari)
    if not (stren < 1) and (intel < 1 ) and (chari < 1):
        return("All stats should be no less than 1")
    if stren > 4 or intel > 4 or chari > 4 :
       return("All stats should be no more than 4")
    if intel + stren + chari != 7 :
        return("The character should start with 7 points")
    return(f"{cname}\nSTR {stren*full_dot}{(10-stren)*empty_dot}\nINT {intel*full_dot}{(10-intel)*empty_dot}\nCHA {chari*full_dot}{(10-chari)*empty_dot}")
cn = input("Enter character name")
cst = input("Enter strength")
cin = input("Enter intelligence")
cch = input("Enter charisma")
print(create_character(cn,cst,cin,cch))


Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) 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 is this if statement checking?

This if statement is saying, “if stren is not less than 1 and if intel is less than 1 and if chari is less than one” because everything between the and operators is being evaluated as a separate condition.

I see. I need to use and in the first if. Need to correct the condition in the second one.

Not sure if you are understanding, so let me restate it:

if [1st condition evaluated] and [2nd condition evaluated] and [3rd condition evaluated]

The 1st condition is correct since you are checking to make sure stren is not less than 1.

I hope that is clearer.

I replaced the second if with this:

if stren < 1 :

    return("All stats should be no less than 1")

elif intel < 1 :

return(“All stats should be no more than 1”)

elif chari < 1 :

return(“All stats should be no more than 1”)

It works in that it lets the code run. It does not satisfy test #8.

please post all your updated code

Please follow this guide to improve the readability of the code. 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 (').

Sorry. Here is the code from start of the function:

def create_character(cname, stren, intel, chari):
    if not isinstance(cname, str):
        return("The character name should be a string")
    if cname == "":
        return("The character should have a name")
    if len(cname) > 10:
        return("The character name is too long")
    if " " in cname :
        return("The character name should not contain spaces")
    if (isinstance(stren,int) or isinstance(intel,int) or isinstance(chari,int)):
        return("All stats should be integers")
    stren = int(stren)
    intel = int(intel)
    chari = int(chari)
#    if not(stren < 1 and intel < 1  and chari < 1 ):
    if stren < 1 :
        return("All stats should be no less than 1")
    elif intel < 1 :
        return("All stats should be no more than 1")
    elif chari < 1 :
        return("All stats should be no more than 1")

if the stats are integers, what do you expect here to happen?
like, if stren is an integer, you get that isinstance(stren, int) is True, so the condition is True, so it runs that return, but they are integers, but it say that they should be integers, but they are integers

return is not a function; it’s a statement.

Can you say what this if statement is doing?

If all three stats are integer, the argument is true, so the return is executed. Not what I want. How about

if not(isinstance(stren,int) and isinstance(intel,int) and isinstance(chari,int)): return(“All stats should be integers”)

When any one of them is not integer or all three, the argument in parens is false. The not reverses it to true so the message is returned. Oops! not when all three are false!

I need to find a better way to do this three-variable test. how about not(A or B or C) where the test is not isinstance(stat,int)? Or an I still confused. Would three separate staatements be better?

I have dug a little deeper and found my problem goes back to type of input.

Added this:

if (isinstance(stren,int) or isinstance(intel,int) or isinstance(chari,int)):
    return("All stats should be integers")
print(isinstance(stren,int), type(stren))
print(isinstance(intel,int), type(intel))
print(isinstance(chari,int), type(chari))

and got this result:

False <class 'str'>
False <class 'str'>
False <class 'str'>

so I need to find a better way for test 7, even though it passed the test! Thanks, your getting me to ask what the ifs were doing led me to the correct problem. Back to thinking and coding...

if the current condition is always wrong, you could flip the whole condition so that it can be always right

with flip I mean flip the boolean vale, with not

Thanks, that is more my programming style. I will try it, with some other fixes.