Build an RPG Character

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 not 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(stat, int) for stat in stats):

    return 'All stats should be integers'

if any(stat<1 for stat in stats):

    return 'All stats should be no less than 1'

if any(stat>4 for stat in stats):

    return 'All stats should be no more than 4'

if sum(stats) != 7:

    return 'The character should start with 7 points'

def stat_bar(value):

    return full_dot\*value + empty_dot\*(10-value)



result = (f"{name}\\\\n" + f"STR {stat_bar(strength)}\\\\n" + f"INT {stat_bar(intelligence)}\\\\n" + f"CHA {stat_bar(charisma)}")

return result

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

What am I doing wrong here? My steps 11 and 12 are not getting done

do you have all these \ here or it is an issue with the forum formatting the code automatically?

maybe post your code again formatting it youtself

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 (').

I am having issue with `RPG step 11 and 12.` 
```
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 not 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(stat, int) for stat in stats):
        return 'All stats should be integers'
    if any(stat<1 for stat in stats):
        return 'All stats should be no less than 1'
    if any(stat>4 for stat in stats):
        return 'All stats should be no more than 4'
    if sum(stats) != 7:
        return 'The character should start with 7 points'
    def stat_bar(value):
        return full_dot*value + empty_dot*(10-value)

    result = (f"{name}\\n" + f"STR {stat_bar(strength)}\\n" + f"INT {stat_bar(intelligence)}\\n" + f"CHA {stat_bar(charisma)}")
    return result
    
print(create_character('ren', 4, 2, 1))
```

why are you escaping the new line characters?

Output `` ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○``` if i use \n it is giving me same error and it give output in new line which shows in example. i tried following :

(1) result = (f"{name}\\n" + f"STR {stat_bar(strength)}\\n" + f"INT {stat_bar(intelligence)}\\n" + f"CHA {stat_bar(charisma)}")                   (2) result = (f"{name}\n" + f"STR {stat_bar(strength)}\n" + f"INT {stat_bar(intelligence)}\n" + f"CHA {stat_bar(charisma)}") 

please stop escaping \n, you need the final string to be on multiple lines

please post your full updated code if you need more help

1 Like

Thank you for assistance. Today before it was not working and i was getting output same as shown in example. Now my code is working with \n . Appreciate your help