Build an RPG Character - Build an RPG Character

Tell us what’s happening:

My code is failing at test 11 and some after as well. Trying to just understand why it is failing at test 11 right now. The code is returning ‘All stats should be integers’ after testing it. I have read through the forums for the past few days trying to figure out why and copying other’s ideas to try to find a solution but I am not sure why my code is displaying ‘All stats should be integers’

Your code so far

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'
    if " " in name:
        return 'The character name should not contain spaces'
    stats = [strength, intelligence, charisma]
    if not all(isinstance(stats, int) for stat in stats):
        return 'All stats should be integers'
    elif stats < 1:
        return 'All stats should be no less than 1'
    elif stats > 4:
        return 'All stats should be no more than 4'
    elif sum(stats) != 7:
        return 'The character should start with 7 points'
    else:
        return 
        'name' 
        '\nSTR '(full_dot*strength)+((10-strength)*empty_dot)
        '\nINT '(full_dot*intelligence)+((10-intelligence)*empty_dot)
        '\nCHA '(full_dot*charisma)+((10-charisma)*empty_dot)

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

Your browser information:

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

Challenge Information:

Build an RPG Character - Build an RPG Character

note that you are failing

  1. When create_character is called with a second, third and fourth argument that are all integers it should not return All stats should be integers .

the one that check that you are not returning the string for valid values

you are testing this, but what is stats?

stats = [strength, intelligence, charisma]

This is my code as of right now after trying different things and now it returns ‘None’ in the terminal

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’

if " " in name:

return ‘The character name should not contain spaces’

stats = \[strength, intelligence, charisma\]

if all (isinstance(stats, int) for stat in stats):

return ‘All stats should be integers’

for stat in stats:

if stat < 1:

return ‘All stats should be no less than 1’

for stat in stats:

if stat > 4:

return ‘All stats should be no more than 4’

if sum(stats) != 7:

return ‘The character should start with 7 points’

else:

return

‘name’

'\nSTR '(full_dot*strength)+((10-strength)*empty_dot)

'\nINT '(full_dot*intelligence)+((10-intelligence)*empty_dot)

'\nCHA '(full_dot*charisma)+((10-charisma)*empty_dot)

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

updated code, but now having issues with tests 18 and 19 only

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’

if " " in name:

return ‘The character name should not contain spaces’

stats = \[strength, intelligence, charisma\]

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

return ‘All stats should be integers’

for stat in stats:

if stat < 1:

return ‘All stats should be no less than 1’

for stat in stats:

if stat > 4:

return ‘All stats should be no more than 4’

if sum(stats) != 7:

return ‘The character should start with 7 points’

else:

return

‘name’

'\nSTR '(full_dot*strength)+((10-strength)*empty_dot)

'\nINT '(full_dot*intelligence)+((10-intelligence)*empty_dot)

'\nCHA '(full_dot*charisma)+((10-charisma)*empty_dot)

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

figured out why it showed ‘None’ in the terminal but still failing test 18 and 19

please post your code formatted so that it is readable:

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

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'
    if " " in name:
        return 'The character name should not contain spaces'
    stats = [strength, intelligence, charisma]
    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
        return 'All stats should be integers'
    for stat in stats:
        if stat < 1:
            return 'All stats should be no less than 1'
    for stat in stats:
        if stat > 4:
            return 'All stats should be no more than 4'
    if sum(stats) != 7:
            return 'The character should start with 7 points'
    else:
        print(name) 
        print('\nSTR '(full_dot*strength+(10-strength)*empty_dot))
        print('\nINT '(full_dot*intelligence+(10-intelligence)*empty_dot))
        print('\nCHA '(full_dot*charisma+(10-charisma)*empty_dot))

create_character('ren', 4, 2, 1)

Bump for help with my code. Still stuck

Hi there,

Your function is not returning anything.

Thats why I am asking for help

This is my updated code after a friend helped me. It is still failling checks 18 and 19

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'
    if " " in name:
        return 'The character name should not contain spaces'
    stats = [strength, intelligence, charisma]
    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
        return 'All stats should be integers'
    for stat in stats:
        if stat < 1:
            return 'All stats should be no less than 1'
    for stat in stats:
        if stat > 4:
            return 'All stats should be no more than 4'
    if sum(stats) != 7:
            return 'The character should start with 7 points'
    else:
        print(name,'\nSTR',(full_dot*strength+(10-strength)*empty_dot),'\nINT',(full_dot*intelligence+(10-intelligence)*empty_dot),'\nCHA',(full_dot*charisma+(10-charisma)*empty_dot))

create_character('ren', 4, 2, 1)

To return something from your function, you need to use a return statement.

Your function is printing the result to the console.

If you want to see what your function returns in the console, test like this:

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

I found out whenever I call out different values outside of the test, the code returns nothing to the console

whenever i change line 24 to ‘return’ instead of ‘print’ the console does not display anything. If i don’t do that and instead add ‘print(create_character(‘ren’, 4, 2, 1))’ at the end, it shows the same results in the console with the addition of ‘None’ at the end

Edit: You return in your function and print your function call to see the results of the return.

like this?

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'
    if " " in name:
        return 'The character name should not contain spaces'
    stats = [strength, intelligence, charisma]
    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
        return 'All stats should be integers'
    for stat in stats:
        if stat < 1:
            return 'All stats should be no less than 1'
    for stat in stats:
        if stat > 4:
            return 'All stats should be no more than 4'
    if sum(stats) != 7:
            return 'The character should start with 7 points'
    else:
        return(name,'\nSTR',(full_dot*strength+(10-strength)*empty_dot),'\nINT',(full_dot*intelligence+(10-intelligence)*empty_dot),'\nCHA',(full_dot*charisma+(10-charisma)*empty_dot))

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

Yes. Now you just need to fix what you’re returning. Your function should return a single string.

ok I will try to figure that out and come back if I need anything more. Thank you

This is where I am at right now. I’m confused a little because I am now outputting a string like I should be and it displays like it’s saying it should

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'
    if " " in name:
        return 'The character name should not contain spaces'
    stats = [strength, intelligence, charisma]
    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
        return 'All stats should be integers'
    for stat in stats:
        if stat < 1:
            return 'All stats should be no less than 1'
    for stat in stats:
        if stat > 4:
            return 'All stats should be no more than 4'
    if sum(stats) != 7:
            return 'The character should start with 7 points'
    else:
        return(name+'\\nSTR'" "+(full_dot*strength+(10-strength)*empty_dot)+'\\nINT'" "+(full_dot*intelligence+(10-intelligence)*empty_dot)+'\\nCHA'" "+(full_dot*charisma+(10-charisma)*empty_dot))

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