Build an RPG Character - Build an RPG Character

@ILM Ok, so I go for “if-if-if …” then “return”.
But with your second comment, in your proposed solution - print(repr(create_character(‘ren’, 4, 2, 1))) - what does the “repr” stand for?
I tried that and still only 1-10 pass, 11-12 fail

So what shall I do? Here is my code. Tests 1-10 pass, 11-12 fail

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 len(name) == 0:
        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 + charisma) != 7:
        return "The character should start with 7 points"
        
    return f"{name}\n STR{(strength*full_dot)+((10-strength)*empty_dot)}\n INT{(intelligence*full_dot)+((10-intelligence)*empty_dot)}\n CHA{(charisma*full_dot)+((10-charisma)*empty_dot)}"
    print(repr(create_character('ren', 4, 2, 1)))

@ILM by the way, I copied your last suggestion including the “repr” word, whose function I do not understand

please write it outside the function, not inside, then you will see the output in the console

do you know how to write something outside the function?

repr transforms the string in the same format you see in test 11, with the \n visible instead of actually going to a new line

Sorry, I am new to IT programming in general and Python in particular. What does that mean to write outside/inside the function?
Regarding “repr”, why would I need to transform the string as you mention?

you should not call the function inside itself, it causes an infinite loop that crashes things (here it does not happen because it’s after the return, but that just means the function call is not doing anything)

write the function call outside the function

in Python that means you need to remove all the spaces at the beginning of the line, and having the p of print being the first character of the line

the indentation is used to indicate if the lines are inside an other block (like a function or if)

so you can compare with expected output written in test 11, so this one: 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'

repr will transform the string to this format so you can compare

if you have doubts about indentation you can review https://www.freecodecamp.org/learn/python-v9/lecture-booleans-and-conditionals/how-do-conditional-statements-and-logical-operators-work and https://www.freecodecamp.org/learn/python-v9/lecture-understanding-functions-and-scope/how-do-functions-work-in-python

Is it what you mean with writing the function call outside the function? Tests 11-12 still do not pass

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 len(name) == 0:
        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 + charisma) != 7:
        return "The character should start with 7 points"

    return f"{name}\n STR{(strength*full_dot)+((10-strength)*empty_dot)}\n INT{(intelligence*full_dot)+((10-intelligence)*empty_dot)}\n CHA{(charisma*full_dot)+((10-charisma)*empty_dot)}"
print(repr(create_character('ren', 4, 2, 1)))

And in the console, I see no particular comment, except a series of W (capital w)

do you see this?

the WWW is going to be fixed soon, if you don’t see the text, try to switch to dark mode, with the current bug the terminal text in light mode is white on white

I switched to night mode, but only see a white rectangle. But the last 2 test #11 and #12 still fail. So what is wrong or what needs to be corrected?

Stop running the tests until you understand the problem.

If you pass the tests somehow and don’t understand the code, what’s the point?

What you’re trying to do now, is print the output of the function so that you can see what’s wrong with it and why it’s failing the test. There’s no reason to expect the test to pass right now.

@pkdvalis I am surprised by your answer. I am asking for help as I do not understand what the problem is and your answer is that I should try to understand. Are you there to help or just to tell me to go away? Moreover, @ILM asked me after I had shared my code and before your reply to change to night mode, suggesting I should see it works. But it does not.
Can you please help instead of sharing vague random comments?

Not really what they said

They said you have extra spaces.

The problem with the terminal is stopping you.

Do you have another editor you can try this in?

can you share where is the print call? there are spaces between the print and the start of the line?

I do not understand what you are asking with “do you have another editor you can try this in?”. What does that mean?
Also, what do you mean with “extra spaces” and “there are spaces between the print and the start of the line?”.
I have shared my code. Can you pls tell me what is wrong instead of coming back continuously with vague answers?

see here that the number of spaces in front of print is the same as in front of return? that means that the print is inside the function

this seems to have been fixed here

now you should be able to see the output of print in the terminal:

in test 11 you are given this string: ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○

you can add print(repr('ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○')) right below the print you have to see them near each other:

notice they are not the same, find the differences, fix your code so to not have those differences

We’re telling you. Can you think about it and try to come up with more thoughtful questions? We’re not being vague but we’re also not going to give you the solution. We will help you to figure out the problem if you work with us.

By “editor” I mean some environment you can type and execute code. The fCC editor you are using to write code is one. I linked another one for you previously to make some tests using the if statement so you could learn about it:

Did you try any of those test to understand the different between if/return and if/else ?

Hi, I tried the other editor (www.online-python.com/) with my entire code, ran the code and got the following outcome:
‘ren\n STR ●●●●○○○○○○\n INT ●●○○○○○○○○\n CHA ●○○○○○○○○○’
So, it seems to work (does not give any other outcome in fCC than WWWW…). However, the outcome should be on 4 different lines, right?
Can you please share indications as to how I can get that? I thought getting different lines was the purpose of \n, or am I wrong?

if you are using repr it’s normal you see the \n, remove repr and you will see the output on multiple lines

the suggestion of using repr was to compare more easily to the given output in test 11, which shows the \n

Ok, so now the outcome shows on 4 different line, but tests 11-12 still fail.
The “ren” is on top but not really aligned with the 3 lines below, maybe that is the reason that the tests fail, or what is wrong?

in this image I am showing you what you can do with repr, confronting the expected output in the test (second line) with your code (first line), did you do any attempt to make them the same since I showed you this?

to have the two lines in your editor just write

print(repr(create_character('ren', 4, 2, 1)))
print(repr('ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'))

note that repr is changing what you are seeing so you can see the spaces better, it’s not changing what the function is returning since you are using it outside the function