Build an RPG character - Build an RPG Character

Tell us what’s happening:

I am having trouble getting past the 9th and 10th tests.

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(name, stre, intel, cha):
    if not isinstance(name, str):
        return "The character name should be a string"
    if len(name) > 10:
        return "The character name is too long"
    if ' ' in name:
        return "The character name should not contain spaces"
    
    if not all(isinstance(x, int) for x in [stre, intel, cha]):
        return "All stats should be integers"
    if min(stre, intel, cha) < 1:
        return "All stats should be no less than 1"
    if max(stre, intel, cha) > 4:
        return "All stats should be no more than 4"
    if stre + intel + cha != 7:
        return "The character should start with 7 points"
    
    rstr = 10 - stre
    rint = 10 - intel
    rcha = 10 - cha

    return f"""\
{name}
STR {stre * full_dot}{rstr * empty_dot}
INT {intel * full_dot}{rint * empty_dot}
CHA {cha * full_dot}{rcha * empty_dot}
"""

print(create_character("ren", 4, 2, 1))




Your browser information:

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

Challenge Information:

Build an RPG character - Build an RPG Character

You wrap the call to the create_character in repr function, that way printed will be such representation of the returned string that’s easier to compare with what is expected by test.

print(repr(create_character("ren", 4, 2, 1)))

It didn’t work. I am still not getting past the last 2 tests

Did you compare what’s printed with what test expects?

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like