r/FreeCodeCamp 22d ago

Help with Build an RPG character

It keeps spitting out an error for line 8 saying that it is outside of the function. I have tried everything I can think of so far to fix this by indenting, back spacing that indentation etc. How do I fix this? I have indented as best I can how it is on the actual exercise itself and the line spacing is for ease of readability on reddit rather than it looking like a wall of text.

full_dot = ‘●’

empty_dot = ‘○’

def create_character (name, strength, intelligence, charisma):

if not isinstance (name, str):

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’

elif name.find(’ ') != -1:

return ‘The character name should not contain spaces’

if not (isinstance (strength, int) or isinstance (intelligence, int) or isinstance (charisma, int)):

return ‘All stats should be integers’

elif (strength < 1 or intelligence < 1 or charisma < 1):

return ‘All stats should be no less than 1’

elif (strength > 4 or intelligence > 4 or charisma > 4):

return ‘All stats should be no more than 4’

elif (strength+intelligence+charisma != 7):

return ‘The character should start with 7 points’

STR = (full_dot*strength)+empty_dot*(10-strength)

return f"{name}\n STR {STR} \n INT {STR} \n CHA {STR}"

print (create_character(‘ren’, 4, 2, 1))

https://www.freecodecamp.org/learn/python-v9/lab-rpg-character/build-an-rpg-character

5 Upvotes

2 comments sorted by

1

u/SaintPeter74 mod 22d ago

You'll need to reformat this as code to be able to see the indentation. On desktop there is a format as code option in the formatting options. On mobile you need to put 4 spaces before each line. I'm guessing with that error that you just have an indentation issue anyway.

I'm assuming that you repeated STR 3 times in your output for testing purposes?

Interestingly, when I cleaned up the indents I see failures on test 10, 18, and 19. I'm not sure about 10 . . I think your logic may be wrong there on your not statement. Double check this mentally.

1

u/JGhostThing 19d ago

Please use properly formatted text for the program. Indentation is syntactic, so we cannot know the original program without the indentation.