Why does it generate this error for me in Build an RPG Character

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

if type(name) is not 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)
if not all(isinstance(x, int) and not isinstance(x, bool) for x in stats):
    return "All stats should be integers."
if any(x < 1 for x in stats):
    return "All stats should be no less than 1."
if any(x > 4 for x in stats):
    return "All stats should be no more than 4."
if sum(stats) != 7:
    return "The character should start with 7 points."

full = "â—Ź"
empty = "â—‹"

def bar(v):
    return full * v + empty * (10 - v)

return "\n".join([
    name,
    "STR " + bar(strength),
    "INT " + bar(intelligence),
    "CHA " + bar(charisma),
])

1 Like

You included a period in the code you posted. It looks to me based off your screenshot that the period is not included in the output the test is looking for. It is a very perticular and exact test and when they are looking for a returned string it needs to be exact down to the puncuation included in the squared off region of the hint or testing module.

1 Like

Also happy coding and glad to have you here if you need more help feel free to reply and I and the others here will do our best to guide you along the way. However we are not permitted o give you direct and exact answers to your problems and instead rely on the Socratic method of teaching.

1 Like

You need to remove the period at the end of the strings returned, definitely.

And you should check your conditions, e.g. if len(name) == 10: should be if len(name) > 10:

Condition if "" in name:

doesn’t really make sense for a non-empty string.

1 Like

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