Build an RPG Character - Build an RPG Character

Tell us what’s happening:

can someone help me figure what’s wrong with this

  1. create_character(‘ren’, 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
  2. When create_character is called with valid values it should output the character stats as required.

Your code so far

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'

    if not isinstance(strength, int) or not isinstance(charisma, int) or not isinstance(intelligence, int):
        return 'All stats should be integers'
    if strength < 1 or charisma < 1 or intelligence < 1:
        return 'All stats should be no less than 1'
    if strength > 4 or charisma > 4 or intelligence > 4:
        return 'All stats should be no more than 4'
    if strength + intelligence + charisma != 7:
        return 'The character should start with 7 points'

    full_dot = '●●●●●●●●●●'
    empty_dot = '○○○○○○○○○○'

    STR_full = full_dot[:strength]
    INT_full = full_dot[:intelligence]
    CHA_full = full_dot[:charisma]

    STR_empty = empty_dot[:(10 - strength)]
    INT_empty = empty_dot[:(10 - intelligence)]
    CHA_empty = empty_dot[:(10 - charisma)]

    return print(name 
    + '\nSTR ' + STR_full + STR_empty
    + '\nINT ' + INT_full + INT_empty
    + '\nCHA ' + CHA_full + CHA_empty)

    


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

To confirm what function returns, it can be wrapped with the print function, ie.:

print("Result: ", create_character('ren', 4, 2, 1))

it still doesn’t work

the output is Result: ren

You have changed the starting code.

what should I need to do now

You will need restore the original values of those global variables and change your approach to creating the returned string.

should I keep these global variables at this position or also move it to original position

and how should I approach the returned string

It wasn’t supposed to make it work, but to show what function returns. I’m getting:

Result: None

This suggests that function is not returning the string, but None instead.

thansk I got the correct answer

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.