I’m not able to complete steps 18 and 19. Feeling lost about what to do. Could anyone help?
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, cha):
points = empty_dot.replace(empty_dot, full_dot)
if not isinstance(name, str):
return 'The character name should be a string'
if name == '':
return 'The character should have a name'
if len(name) > 10:
return 'The character name is too long'
if ' ' in name:
return 'The character name should not contain spaces'
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(cha, int):
return 'All stats should be integers'
if strength < 1:
return 'All stats should be no less than 1'
if intelligence < 1:
return 'All stats should be no less than 1'
if cha < 1:
return 'All stats should be no less than 1'
if strength > 4:
return 'All stats should be no more than 4'
if intelligence > 4:
return 'All stats should be no more than 4'
if cha > 4:
return 'All stats should be no more than 4'
if strength + intelligence + cha == 7:
return
else:
return 'The character should start with 7 points'
if full_dot:
if strength + 1:
points =+ 1
return
if intelligence + 1:
points =+ 1
return
if cha + 1:
points =+ 1
return
return f'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'
create_character('ren', 4, 2, 1)
print(f'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○')
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
I think I’ve fixed it, but I still have no idea how to proceed with the 18 and 19 steps.
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, cha):
if not isinstance(name, str):
return 'The character name should be a string'
if name == '':
return 'The character should have a name'
if len(name) > 10:
return 'The character name is too long'
if ' ' in name:
return 'The character name should not contain spaces'
if not (isinstance(strength, int) or isinstance(intelligence, int) or isinstance(char, int)):
return 'All stats should be integers'
if (strength or intelligence or cha) < 1:
return 'All stats should be no less than 1'
if (strength or intelligence or cha) > 4:
return 'All stats should be no more than 4'
if strength + intelligence + cha != 7:
return 'The character should start with 7 points'
Just tackle it one line at a time based on the instructions given to build the return string:
If all values pass the verification, the function should return a string with four lines:
the first line should contain the character name
lines 2-4 should start with the stat abbreviation, STR, INT or CHA (in this order), then a space, and then a number of full dots (●) equal to the value of the stat, and a number of empty dots (○) to reach 10. Example: if the value of strength is 3 there must be 3 full dots followed by 7 empty dots. The dots are given in the editor.
You will need to use the global variables to build the dynamic dots — either full or empty – based on the specific stat value.
for each point the user gives to any of the three aspects it should replace an empty dot by a full_dot. I think I got this logic, I just don’t know how to connect it with the theoretical input.