Build an RPG character - Build an RPG Character

Tell us what’s happening:

Stuck on passing 6-10. I made a set for the base stats inputted and i feel that the ‘for’ loop lets me cycle through the data set to let my ‘if’ statement check for the value. I checked that the string output for each one matches the prompt. not really sure where to start for the trouble shooting because i feel like logic is right.

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(name,strength,intelligence,charisma):
   
 # Validate name is useable
    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'
 
 # Validate the base stats are numbers
    if not isinstance(strength,int) or isinstance(intelligence,int) or isinstance(charisma,int):
        return'All stats should be integers'
        
 # Make a data set to check through all stats       
    base_stats=[strength,intelligence,charisma]
    for each_stat in base_stats:
        if each_stat < 1:
            return'All stats should be no less than 1'
        
        if each_stat > 4:
            return'All stats should be no more than 4'
        
        if sum(base_stats.values()) != 7:
            return 'The character should start with 7 points'
            
 # Return bar
    Str_bar = strength*full_dot + (10-strength)*empty_dot
    Int_bar = intelligence*full_dot + (10-intelligence)*empty_dot
    Cha_bar = charisma*full_dot + (10-charisma)*empty_dot

    display = name + "/n"
    display += Str_bar + "/n"
    display += Int_bar + "/n"
    display += Cha_bar + "/n"

    return display



        

Your browser information:

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

Challenge Information:

Build an RPG character - Build an RPG Character

when I try create_character("ren", 0, 2, 1) expecting the message 'All stats should be no less than 1' I get instead 'All stats should be integers'

Not sure where to start checking the logic, would the problem be with validating the stats are numbers or would the problem be with the data set and checking the thresholds of the base_stats?

if I tell you the problem is the logical operators, would you be able to continue from there?

just so i am clear by what you mean with logical operators, the issue is with my understanding of ‘or’ , ‘not’, ‘truthy’ and ‘false’?

the logical operators you are using in the line with the issue are not and or, mainly I think with your understanding of operator precedence

if you add

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

right before the if statement you will see they are giving the expected values

you mean like this? Remove the ‘or’ so the ‘not’ applies to each check for an integer?

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

the issue is that the not has higher precedence, so what you wrote was like if (not ...) or (...) or (...) while maybe you wanted if not (or ... or ... or)
knowing this, you should still be able to solve this with a single if

that makes perfect sense! thank you! i didn’t realize that logical operator does not apply to the whole statement!

Still failing 7,9,10 but id like to try tacking the issue before asking for help. Should i make a new post if I’m still struggling with those parts?

I was going to suggest something similar since I also had a similar issue yesterday with the not statement, mine ended up something like…

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

continue asking here, it’s the same challenge

mine worked after I wrote it like that. my issue is on my other post on challenge 9, if you had time you could check it out please :slight_smile:

you don’t need to ask on someone else’s post, someone will take a look at yours

yes sorry, i thought you were replying to me with your comment but I realize you were replying to the OP. my mistake!