Build an RPG Character - Build an RPG Character

Tell us what’s happening:

Hi, can someone tell me if I made errors in my code ? I can’t get any test to pass even though the seems logical. but everytime I check it, it tells me that my code raised errors.

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(name, strength, intelligence, charsima):
    
    if isinstance(name, str) == False:
        return 'The character name should be a string'
    if name == '':
        return 'The character should have a name'
    if len(name) > 10:
        return 'The character name is too long'
    if ' ' in 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 < 1 or intelligence < 1 or charisma < 1:
        return 'All stats should be no less than 1'
    if strength > 4 or intelligence > 4 or charisma > 4:
        return 'All stats should be no more than 4'
    if strength + intelligence + charsima != 7:
        return 'The character should start with 7 points'
        else:
         return (character_name)
         return ('STR ' + strength*full_dot + (10-strength)*empty_dot)
         return ('INT ' + intelligence*full_dot + (10-intelligence)*empty_dot)
         return ('CHA ' + charisma * full_dot + (10-charisma)*empty_dot)

    
    

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 @LTr_08 !

Traceback (most recent call last):
  File "main.py", line 23
    else:
    ^^^^
SyntaxError: invalid syntax

I’m seeing this error in the console.

And remember that when your code gets to a return, processing will stop there.

Happy coding!

I corrected the indentation with the else statement at the end. But I didn’t know that my code would stop as soon as it reaches a return ?

Does that mean that I have to replace these returns for print instead? And do I have to use return at the end of the fundtion ?

If it didn’t, you would see all of those validation messages even if the parameters were valid.

No. Your function should return the stats string if there are no validation errors.

You said that the code stops processing once it gets to a return, what did you imply ? The function doesn’t stop after one return function right ? Sorry if I’m bothering.

You are not bothering me. This is an important point to understand.

Look at your first if statement, please. If you call your function with a number for the name parameter (create_character(2,4,2,1)), then you would expect name not to validate, right? So, immediately, your code returns the message, “The character name should be a string” and it stops processing right there. It never “sees” any of the following if statements.

Does that make sense?

Ohhh okay thanks for the reply. But then how can my code continue to read the following lines if it stops after a return ? I don’t want the solution but this seems weird because that means that every function just stops after a return ? Does that mean I can’t use return ?

In this particular code, it only stops processing if the validation condition is true.

If there is a name and name is a string and name is not over 10 characters long and there are no spaces in name, your code will not go to the return statements.

Thank you, it’s much clearer now.

I also managed to “solve” the challenge but I had to copy some code from other posts “(

I really wanted to solve it on my own but that’s alright :sob:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.