Build an RPG Character - Build an RPG Character

Tell us what’s happening:

My code is failing in test 2,3,4,7,8,9,10.

Need help to understand why

def create_character(name, strength, intelligence, charisma):

# Name validation (exact required messages)
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."

Your code so far

def create_character(name, strength, intelligence, charisma):

    # Name validation (exact required messages)
    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)

    # Stat validation (exact required messages, in required order)
    if not all(isinstance(stat, int) and not isinstance(stat, bool) 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_dots(value):
        full_dot = "●"
        empty_dot = "○"
        return full_dot * value + empty_dot * (10 - value)

    return "\n".join([
        name,
        f"STR {stat_dots(strength)}",
        f"INT {stat_dots(intelligence)}",
        f"CHA {stat_dots(charisma)}"
    ])

Your browser information:

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

Challenge Information:

Build an RPG Character - Build an RPG Character

Try testing your function.

Call your function with test data and print the result.

  1. When create_character is called with a first argument that is not a string it should return The character name should be a string.

What happens when you call your function and the first argument is not a string?

1 Like

Hi !

The problème is identation of différents if statement.

The second if is normaly inside the first and so on to reach at the last condition.

And you go back which the else statement until the first if

1 Like

Tested the functions and they are working properly.

Tested the fuction like this and everything works.

print(create_character(“Hero”, 3, 2, 2))

print(create_character(“”, 3, 2, 2))

print(create_character(“VeryLongName”, 3, 2, 2))

print(create_character(“Hero Name”, 3, 2, 2))

print(create_character(“Hero”, 0, 2, 2))

Not true. The if statements in this code are all indented properly.

Please stop giving campers inaccurate advice.

1 Like

@pkdvalis wanted you to call create_character by passing in something other than a string as the first argument to show you that you have an issue with your validation statements. Please make sure they match exactly to the instructions. (You have something extra there.)

1 Like

Tested with this:
print(create_character(“Hero”, 3, 2, 2))

print(create_character(‘’, 3, 2, 2))

print(create_character(“Hero Name”, 3, 2, 2))

print(create_character(“Hero”, 0, 2, 2))

print(create_character(123,3,2,2))

and this were results:

Hero
STR ●●●○○○○○○○
INT ●●○○○○○○○○
CHA ●●○○○○○○○○
The character should have a name.
The character name should not contain spaces.
All stats should be no less than 1.
The character name should be a string.

So how do those validation messages compare to the validation messages in the instructions? Do you see the difference? And it looks like you have an extra line in the string returned by your function.

1 Like

Found the problem is the problem was the dot at end of the sentences…. and this soo annoying.

2 Likes