Build an RPG Character - Build an RPG Character

Tell us what’s happening:

I have been able to pass all the tests, except for 11 and 12 (both of which involve being able to get the appropriate out to show on the terminal. I have been able to get it to show the proper output, but not the error messages (“name must be a string”, “STR must be an integer”, etc.) unless I make the “print” on line 39 (the second to last line) a “return” and put a “print” in front of the function on line 40 (which defeats the purpose of the function). I suspect I am supposed to expand line 39 with a conditional, but I am not sure what it should be.

Your code so far

full_dot = '●'
empty_dot = '○'
def create_character(name, STR, INT, CHA):
    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"
    if not isinstance (STR, int):
        return "All stats should be integers"
    if not isinstance (INT, int):
        return "All stats should be integers"
    if not isinstance(CHA, int):
        return "All stats should be integers"
    if STR<1:
        return "All stats should be no less than 1"
    if INT<1:
        return "All stats should be no less than 1"
    if CHA<1:
        return "All stats should be no less than 1"
    if STR>4:
        return "All stats should be no more than 4"
    if INT>4:
        return "All stats should be no more than 4"
    if CHA>4:
        return "All stats should be no more than 4"
    if STR+INT+CHA!=7:
        return "The character should start with 7 points"
    def STR_visual(STR):
        return STR*full_dot+(10-STR)*empty_dot
    def INT_visual(INT):
        return INT*full_dot+(10-INT)*empty_dot
    def CHA_visual(CHA):
        return CHA*full_dot+(10-CHA)*empty_dot
    character_stats=(f"{name}\nSTR{STR_visual(STR)}\nINT{INT_visual(INT)}\nCHA{CHA_visual(CHA)}")
    print(character_stats)
create_character("ren",4,2,1)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Build an RPG Character - Build an RPG Character

what is your function returning?

Welcome to the forum @sean.rittner1125 !

What does create_character return?

Try adding this code to your script file to compare actual and expected.

print(repr(create_character("ren",4,2,1)))

print(repr('ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'))

The function returns the following:

ren
STR●●●●○○○○○○
INT●●○○○○○○○○
CHA●○○○○○○○○○

However, if I change one of the variables to be against the rules I coded in, it will only return a blank screen, without returning the intended message.

no, it doesn’t, check with

print("return value=", repr(create_character("ren",4,2,1)))

so that line of code you indicated works as expected. Should I add a line to my code that indicates like the below?:

if no return value:
    print(character_stats)

Your function is not returning anything. A print() function is not the same as a return statement.

that would not help, it’s still not returning

do you expect to see your function return None?

No. The line of code you offered printed the appropriate output (the name and stats represented by the dots), along with the proper error messages whenever an improper value was placed as an argument.

yes, it prints, it does not return

use print("return value=", repr(create_character("ren",4,2,1))) to see that it returns None

Noted. Is there something I should do to make it so that there is a return value? I could instead have it be “return character_stats” or should I write a line of code that ensure that the previous return values print .

Your function already returns many things, but it can only return once.

Sounds like a good idea.

Check the instructions for what you need to return or print()

There are no instructions that ask me to print. In that case, should the print function just be used to help confirm whether the rest of the code is behaving? I have tried to make it so where it is “return charatacter_stats” and then I print the create_character function with the appropriate values. and while that shows up the appropriate output on the terminal it does not satisfy the assignment requirements. Is the second to last line (concerned with the character_stats) where my problem is, or is it something wrong I have been doing through the entire code?

yes, print is a great debugging tool

share your updated code for more help

Yes, exactly. You can also print your function call when you want to see what your function is returning:

print(function("arg", 2))

Can you share your updated code?

This if the code as it exists right now. I was thinking, might I need to use the elif or else function so that the codes knows to return the character_stats if the other conditionals dont return anything?

full_dot = '●'
empty_dot = '○'
def create_character(name, STR, INT, CHA):
    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"
    if not isinstance (STR, int):
        return "All stats should be integers"
    if not isinstance (INT, int):
        return "All stats should be integers"
    if not isinstance(CHA, int):
        return "All stats should be integers"
    if STR<1:
        return "All stats should be no less than 1"
    if INT<1:
        return "All stats should be no less than 1"
    if CHA<1:
        return "All stats should be no less than 1"
    if STR>4:
        return "All stats should be no more than 4"
    if INT>4:
        return "All stats should be no more than 4"
    if CHA>4:
        return "All stats should be no more than 4"
    if STR+INT+CHA!=7:
        return "The character should start with 7 points"
    def STR_visual(STR):
        return STR*full_dot+(10-STR)*empty_dot
    def INT_visual(INT):
        return INT*full_dot+(10-INT)*empty_dot
    def CHA_visual(CHA):
        return CHA*full_dot+(10-CHA)*empty_dot
    character_stats=(f"{name}\nSTR{STR_visual(STR)}\nINT{INT_visual(INT)}\nCHA{CHA_visual(CHA)}")  
    return character_stats
print(create_character("ren",4,2,1))

look closely at the output printed in the terminal, do you have all the needed spaces?

Yes. That worked. Thank you very much!