Tell us what’s happening:
I don’t know what it is wrong, I’ve even used the repr() function and the output stills the same. It looks fine but the test tell me it’s wrong, I’ve had pass the others tests but I’m struggling with this one
- When create_character is called with valid values it should output the character stats as required.
Your code so far
full_dot = '●'
empty_dot = '○'
def validate_name(name):
if not isinstance(name, str):
return False,'The character name should be a string'
elif len(name) >= 10:
return False,'The character name is too long'
elif " " in name:
return False,'The character name should not contain spaces'
return True, ''
def validate_stats(strength, intelligence, charisma):
if not all(isinstance(x, int) for x in (strength, intelligence, charisma)):
return False,'All stats should be integers'
if any(x < 1 for x in (strength, intelligence, charisma)):
return False,'All stats should be no less than 1'
if any(x > 4 for x in (strength, intelligence, charisma)):
return False,'All stats should be no more than 4'
if (strength + intelligence + charisma) != 7:
return False,'The character should start with 7 points'
return True, ''
def create_character(name, strength, intelligence, charisma):
# Validation
ok_name, error_name = validate_name(name)
ok_stats, error_stats = validate_stats(strength, intelligence, charisma)
if not ok_name:
return error_name
if not ok_stats:
return error_stats
# Showings Stats
max_dot = 10
points_stat_strength = strength * full_dot
points_stat_intelligence = intelligence * full_dot
points_stat_charisma = charisma * full_dot
rest_points_strength = (max_dot - strength) * empty_dot
rest_points_intelligence = (max_dot - intelligence) * empty_dot
rest_points_charisma = (max_dot - charisma) * empty_dot
line_str = 'STR ' + points_stat_strength + rest_points_strength
line_int = 'INT ' + points_stat_intelligence + rest_points_intelligence
line_cha = 'CHA '+ points_stat_charisma + rest_points_charisma
final_string = '\n'.join([name , line_str, line_int, line_cha])
return final_string
# print(repr(create_character("ren", 4,2,1)))
print(create_character("ren", 4,2,1))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
Challenge Information:
Build an RPG character - Build an RPG Character