Stuck on passing 6-10. I made a set for the base stats inputted and i feel that the ‘for’ loop lets me cycle through the data set to let my ‘if’ statement check for the value. I checked that the string output for each one matches the prompt. not really sure where to start for the trouble shooting because i feel like logic is right.
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name,strength,intelligence,charisma):
# Validate name is useable
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'
# Validate the base stats are numbers
if not isinstance(strength,int) or isinstance(intelligence,int) or isinstance(charisma,int):
return'All stats should be integers'
# Make a data set to check through all stats
base_stats=[strength,intelligence,charisma]
for each_stat in base_stats:
if each_stat < 1:
return'All stats should be no less than 1'
if each_stat > 4:
return'All stats should be no more than 4'
if sum(base_stats.values()) != 7:
return 'The character should start with 7 points'
# Return bar
Str_bar = strength*full_dot + (10-strength)*empty_dot
Int_bar = intelligence*full_dot + (10-intelligence)*empty_dot
Cha_bar = charisma*full_dot + (10-charisma)*empty_dot
display = name + "/n"
display += Str_bar + "/n"
display += Int_bar + "/n"
display += Cha_bar + "/n"
return display
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Not sure where to start checking the logic, would the problem be with validating the stats are numbers or would the problem be with the data set and checking the thresholds of the base_stats?
you mean like this? Remove the ‘or’ so the ‘not’ applies to each check for an integer?
if not isinstance(strength,int):
return'All stats should be integers'
if not isinstance(intelligence,int):
return'All stats should be integers'
if not isinstance(charisma,int):
return'All stats should be integers'
the issue is that the not has higher precedence, so what you wrote was like if (not ...) or (...) or (...) while maybe you wanted if not (or ... or ... or)
knowing this, you should still be able to solve this with a single if