Build an RPG Character - Build an RPG Character (Step 4)

Tell us what’s happening:

I am stuck on step 4, where if one or more stats are less than 1, the code returns “all stats should be no less than 1”. I am not sure how to format the “or more” part. I have used OR statements and it works that when one of the stats is less than 1, the function returns the statement. But if all stats are above 1 it still returns “all stats should be no less than 1”.

Your code so far

full_dot = '●'
empty_dot = '○'
character_name = 'Sunny'
strength = 2
intelligence = 2
charisma = 2

def create_character(character_name, strength, intelligence, charisma):
    if not isinstance(character_name,str):
        return('The character name should be a string')
    if character_name == '':
        return('The character should have a name')
    if len(character_name) >10:
        return('The character name is too long')
    if " " in character_name:
        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 or intelligence or charisma <1:
        return('All stats should be no less than 1')
    if strength or intelligence or chairsma >4:
        return('All stats should be no more than 4')
    if sum(strength, intelligence, charisma) != 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/146.0.0.0 Safari/537.36

Challenge Information:

Build an RPG Character - Build an RPG Character

Welcome to the forum @Derrya !

Your if statements here are not doing what you intend since the only stat being checked as less than 1 or greater than 4 is charisma.

Happy coding!

I tried putting a <1 before each stat, but that didn’t end up working when I did the same thing for the next step (If one or more stats are more than 4, the function should return All stats should be no more than 4.) Could you give me a hint as to what to change?

Please post your updated code.

Your code looks okay to me (can’t test properly from a screenshot). What errors are you getting?

Sorry, I am not sure how to upload my code directly. I tried copying and pasting it in a comment but the indents were not as clear on here as there are in the activity. Here are a couple of screenshots of the error messages I got:

(second screenshot in subsequent reply)

This is not the way to give your function parameters a value.

Instead, you should call your function and pass in the values like this: print(create_character('ren', 4,2,1))

The function call is wrapped in print() so you can see what it returns in the console.

You have a typo in charisma.

This is incorrect syntax for sum(). I suggest using what you understand to get the sum of the stats.

In the future, 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 (').

1 Like