Build an RPG Character - Build an RPG Character

not necessarily, no
you already used a long series of ifs and never elif
remember that a return stops execution of the function
you can just write in the function directly, without creating a new block

So, here is my complete code for tests 1-10

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
    if (name) is not 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"

Based on that, can I go for tests 11-12? I assume I should start with “else” right?

I just answered that

Elif determines the result I want to get if the condition is not met. Do I have to use elif for each condition? Is it what you suggest? Can you please share the syntax for elif?

I am saying you do not need to, because so far you have always used if

having the return inside the if means that only the first if that has a True condition, because the function stops

using elif is mandatory when you do not have returns inside the if, but you want only the code inside the first condition that is True to run

so you do not need to use elif

but you can find the elif syntax in the same lesson about if https://www.freecodecamp.org/learn/python-v9/lecture-booleans-and-conditionals/how-do-conditional-statements-and-logical-operators-work

Sorry, I am getting confused. Assuming my code is correct for tests 1-10, I believe I should now start with “else”. Basically, if any of the previous conditions is met, there is a specific outcome that appears. But if none of the above conditions is met, then I define what should appear with the “else” function. Am I wrong?

You can but you don’t need to, you can just write outside the if inside the function, because there is no case in which the code below would run if the condition is True

if True:
  print("I am executed")
print("I am also executed")

vs

if True:
  print("I am executed")
else:
  print("I am not executed")

vs

if True:
  print("I am executed")
  return "I am executed"
print("I am not executed")

your code is like the last one

Not sure why you keep asking about this. Does it pass the tests?

Yes and no.

if True:
    return "that"
else:
    return "something"
if True:
    return "that"

return "something"

Anything different in the functioning of these two blocks of code?

Compare with these two:

if True:
    print("that")
else:
    return "something"
if True:
    print("that")

return "something"

Remember that return ends and exits the function and no more code runs after that.

I am trying to figure out what you mean. Without proper and clear explanation and no prior experience, it is almost impossible to figure out how to solve this puzzle.
Do I understand well that I should use print as outcome of each if, and then, in all other cases where conditions are not met, go for else with a return?

No. The instructions explicitly ask you to return those values.

def test():
    if True:
        return "that"
    else:
        return "something"
        
print(test())

Copy this block of code and run it here: https://www.online-python.com/

Try changing True to False

def test():
    if True:
        return "that"
    
    return "something"
        
print(test())

Now test this block of code without the else and test that.

Try changing True to False

Ok. So, now this is my code for tests 1-10 and they ALL PASS for the first time (1 to 10)

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"

Now, I want to write the code for 11 and 12. I start with else, right? Or not?

We have tried to explain about this.

I’m not going to tell you how to code it before you even start. Try it, if it works great. If not, try to figure it out.

So, my tests 1 to 10 pass. Here is my code for the whole exercise, including the code for tests 11-12. They do not pass but I see no comment in the console.

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"
    else:
        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(create_character('ren', 4, 2, 1))

How can you test your function and see what it returns?

I do not understand what you are asking

Easier to answer if you can tell me which part you don’t understand

You have written a function. However, if you don’t call the function, it will never run.

How do you call that function with test data and see the result?

I can see you are trying to do that here:

But there’s something wrong with this line. Are you able to see what’s wrong with it?

Where is it? In the context of the function you’ve written?

I would not use an else

the reason I would not use an else, is because you have written a bunch of if and never chained them

an else would be the last in a chain of if/elif/else

but as you have not created a chain, that looks weird

consider you want your code to print one of "a"", "b" and "c"

would you write

if True:
  print("a")
if True:
  print('b')
if True:
  print('c')

or

if True:
  print("a")
elif True:
  print("b")
else:
  print("c")

there is a different in what is printed?


now, what about if you want to return only one between "a", "b", and "c"?

if True:
  return "a"
if True:
  return 'b'

return 'c'

or

if True:
  return  "a"
elif True:
  return "b"
else:
  return "c"

your code is like the first of these two, reason for which I would not use else, but do you think there is a difference in what the function would return?

Regarding the if-elif-else comment by @ILM, do you mean that I should use the code below?
Regarding the comment on calling the function by @pkdvalis, do you mean I should call it like this?
The code pass tests 1-10, only 11-12 still fail, like before

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
    if (not isinstance (name, str)):
        return "The character name should be a string" 
    elif len(name) == 0:
        return "The character should have a name"
    elif len(name) > 10:
        return "The character name is too long"
    elif " " 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"
    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"
    else:
        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)}"
        create_character('ren', 4, 2, 1)
        print (create_character)

I do not mean that you should use one version over the other, I mean that you should use one or the other, not mix the two

if you want to use else it makes sense to put it at the end of a chain of if/elif/elif…/else like you did now, like

if not that you have two chains

this one is an if not an elif, it should be one chain only

if you use many ifs, it does not make sense to add an else at the end, you can just write the last return without an else

like

You can choose one or the other, they are both common patterns

why are these two lines inside the function? these should not be inside the function

you should have print(repr(create_character('ren', 4, 2, 1))) after the function (at the start of the line)

then it shows you where you have extra spaces confronted with the expected solution given in test 11 of 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○’