Build an RPG Character - Build an RPG Character

Tell us what’s happening:

I need assistance with moving to step 4. So far, I found the first two steps easy; however, I am lost when it comes to step 4, since it requires those stats.
I guess I was wondering how I would go about that?

What I have

Your code so far

def create_character (character_name, strength, intelligence, charisma):
    if  not isinstance (character_name, str):
        return ('The character name should be a string')
    if ' ' in character_name:
        return ('The character should have a name.')
    if len(charcter_name) > 10:
        return 'The character name is too long'
    if character_name == " ":
        return ('The character name should not contain spaces')
        
    
    

    



Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build an RPG Character - Build an RPG Character

Hi @Iceeman117 ,

I suggest reviewing the third user story. Test your code. What happens when you call your function like this?

print(create_character(",4,2,1))
print(create_character("my dog",4,2,1))

Happy coding!

1 Like

Yeah i have some advice here as this had stumped me several times. work through the user story, write out your code and keep a print(create_character(‘ren’, 4, 2, 1)) at the bottom of the code so you can compare it to what is supposed to be returned in the user story. This also allows you to see the errors in real time. Just work through the user story and keep that printed and then check your code periodically. Don’t use the tests to check after every line as this will cause you some confusion on this test as well as some of the others in the future.

just to get a confirmation. Am I on the right track for the most part?

def create_character (character_name, strength, intelligence, charisma):
    if  not isinstance (character_name, str):
        return ('The character name should be a string')
    if ' ' in character_name:
        return ('The character should have a name.')
    if len(charcter_name) > 10:
        return 'The character name is too long'
    if character_name == " ":
        return ('The character name should not contain spaces')
       
stats = {'STR':strength, 'INT':intelligence, 'CHA': charisma}

print(create_character(" ren ", 4, 2, 1))

mainly the stats part? Because the console shows that there is an error, which makes me think:

  1. I’m on the wrong path
  2. the syntax format is wrong

checking now I will update this reply in a few minutes

What did you discover when you tested with this code?

Is your stats variable assignment inside the function?

1 Like

What I am seeing right now is that the error is that your parameter is not defined due to the stats variable. put a # at the beginning of this line to comment it out for the time being so it is ignored. Also you have a typo in the line:

if len(charcter_name) > 10:

next thing i see and it may still work without changing this but the if statements, In my opinion, should read if: elif: elif: elif: and then an else: at the bottom.

and temporarily put a return true in your final else: clause just to verify whether the code is passing through the if statements properly. Then continue to work through the story. I may have given away more than I should have here but I felt like it was needed information to pass along to you.