Tell us what’s happening:
test no. 5 is always wrong, is there something wrong in my code?
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(n, s, i, c):
# Check name first
if not isinstance(n, str):
return 'The character name should be a string'
if len(n) > 10:
return 'The character name is too long'
if ' ' in n:
return 'The character name should not contain spaces'
# Check if stats are valid integers
# First, convert everything to string for consistent checking
for stat_value in [s, i, c]:
try:
# Try to convert to int regardless of original type
int(stat_value)
except (ValueError, TypeError):
return 'All stats should be integers'
# Now safely convert them to integers
s = int(s)
i = int(i)
c = int(c)
# Check ranges
if s < 1 or i < 1 or c < 1:
return 'All stats should be no less than 1'
if s > 4 or i > 4 or c > 4:
return 'All stats should be no more than 4'
total = s + i + c
if total != 7:
return 'The character should start with 7 points'
# Calculate dots
rs = 10 - s
ri = 10 - i
rc = 10 - c
return f'''{n}
STR {s * full_dot}{rs * empty_dot}
INT {i * full_dot}{ri * empty_dot}
CHA {c * full_dot}{rc * empty_dot}'''
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