I cannot seem to get stats to work and I cannot for the life of me understand I have checked the web, my notes and I just don’t seem to see what I did wrong.
Your code so far
full_dot = '●'
empty_dot = '○'
def validate_name(name):
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 '' in name:
return 'The character should have a name'
def validate_stats(strength, intelligence, charisma):
for stat in (strength, intelligence, charisma):
if not isinstance(stat, int):
return 'All stats should be integers'
for stat in (strength, intelligence, charisma):
if stat < 1:
return 'All stats should be no less than 1'
for stat in (strength, intelligence, charisma):
if stat > 4:
return 'All stats should be no more than 4'
if strength + intelligence + charisma != 7:
return 'The character should start with 7 points'
def create_dots(stat):
return stat * full_dot + empty_dot * (10 - stat)
def create_character(name, strength, intelligence, charisma):
name_error = validate_name(name)
if name_error:
return name_error
stats_error = validate_stats(strength, intelligence, charisma)
if stats_error:
return stats_error
return (
f'{name}\n'
f'STR {create_dots(strength)}\n'
f'INT {create_dots(intelligence)}\n'
f'CHA {create_dots(charisma)}'
)
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 OPR/126.0.0.0
I’m still having trouble passing steps 7-12 which I think is basically saying that my validate stats function isn’t working. I’ve been fiddling with it and I don’t really see what I did wrong.
I love you. Alright that helped a ton. Now just have to fix it to actually print ‘The character should have a name’. lol
This helped a ton I felt so stupid.
What’s the requirement of the first test that fails?
Are there any errors or messages in the console?
Check the related User Story and ensure it’s followed precisely.
What line of code implements this?
What is the result of the code and does it match the requirement? (what happens when you test you program with input?)
3, 7, 9 are the only ones I have left.
it’s when it’s an empty string it’s supposed to return ‘The character should have a name’ I have checked spelling and tried a few different edits. It’s why I used an empty string the first time but that throws far more errors. I’m not really sure how I work around it.
But what should do to detect no name if I cannot use an empty string. Or if that is the way then why does that suddenly break the rest of my code. I don’t see the connection if that’s what it is. I’m sorry if I’m a little thick. xD
this is an example of a first test to see if your idea works, try it, do you get once True and once False? yes? good, no? you need to check in an other way
name_empty_string = ""
name_correct = "brigitte"
print("" in name_empty_string)
print("" in name_correct)