Build an RPG Character - Build an RPG Character

Tell us what’s happening:

I’m stuck on the part to output the character info correctly, I’ve tried every way I can think of but I don’t know what exact part is wrong, the validations are all correct there’s just an error of output.

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(name, strength, intelligence, charisma):
    #validating name
    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'
    #validating stats
    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'
    stats = strength + intelligence + charisma
    if stats != 7:
        return 'The character should start with 7 points'
    
    return name
    for i in range(strength):
        STR = STR + full_dot
    for i in range(10 - strength):
        STR += empty_dot
    for i in range(intelligence):
        INT = INT + full_dot
    for i in range(10 - intelligence):
        INT += empty_dot
    for i in range(charisma):
        CHA = CHA + full_dot
    for i in range(10 - charisma):
        CHA += empty_dot
    return name

    return (f'{name} \nSTR{strength}\ nINT{intelligence} \nCHA{charisma}')

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/146.0.0.0 Safari/537.36

Challenge Information:

Build an RPG Character - Build an RPG Character

Hi @selina_chen ,

Will your code ever get past the return statement?

Happy coding!

could you give me a hint on how to check that?

What does return do? What are you seeing printed in the console with your existing function call? Try adding print('in here") after your return statement? Do you see anything in the console?

after the return name no, but i don’t understand what other code i could use to replace that

You need to build a string that contains the stats with the full and empty dots based on the stat’s value. Refer to the instructions. Then return that string and nothing else.

I resolved that problem, the only issue now is that when I return the output it skips a line instead of saying ‘\nSTR’ etc.

Please post your updated code to show what you tried.

#returning character profile

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

INT = full_dot \* intelligence + empty_dot \* (10-intelligence)

CHA = full_dot \* charisma + empty_dot \* (10-charisma)

char_info = f'{name} \\nSTR{STR} \\nINT{INT} \\nCHA{CHA}'

return char_info

And what does that string look like in the console?

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

And how does that compare to what is expected based on the instructions?

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

Do you see the difference?

This is what is expected:

ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○

However the ‘\n’ makes the output skip a line that’s how mine works