I’m assuming the reason for step 7 and on is failing is because I can’t write my if statements the way they are but google searches tell me I can so I’m lost again
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
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 not isinstance(intelligence,int) or not isinstance(charisma,int):
return('All stats should be integers')
if strength < 1 or intelligence < 1 or charisma < 1:
return('All stats should be no less than 1')
if strength > 4 or intelligence > 4 or charisma > 4:
return('All stats should be no more than 4')
total=strength + intelligence + charisma
if total != 7:
return('The character should start with 7 points')
final_strength = 'STR', (full_dot * strength) + (empty_dot * (10-strength))
final_intelligence = 'INT', (full_dot * intelligence) + (empty_dot * (10-intelligence))
final_charisma = 'CHA', + (full_dot * charisma) + (empty_dot * (10-charisma))
return(name/final_strength/final_intelligence/final_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/145.0.0.0 Safari/537.36 Edg/145.0.0.0
I have done that and know have these errors but everything I can find online for an explanation is I’m trying to do arithmetic to strings which isn’t allowed
Traceback (most recent call last):
File “main.py”, line 31, in
File “main.py”, line 28, in create_character
TypeError: unsupported operand type(s) for /: ‘str’ and ‘tuple’
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
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 not isinstance(intelligence,int) or not isinstance(charisma,int):
return('All stats should be integers')
if strength < 1 or intelligence < 1 or charisma < 1:
return('All stats should be no less than 1')
if strength > 4 or intelligence > 4 or charisma > 4:
return('All stats should be no more than 4')
total=strength + intelligence + charisma
if total != 7:
return('The character should start with 7 points')
final_strength = 'STR', (full_dot * int(strength)),(empty_dot * (10-int(strength)))
final_intelligence = 'INT', (full_dot * int(intelligence)),(empty_dot * (10-int(intelligence)))
final_charisma = 'CHA', (full_dot * int(charisma)),(empty_dot * (10-int(charisma)))
return(name/final_strength/final_intelligence/final_charisma)
print(create_character('ren',4,2,1))
you may want to review how to concatenate strings, this does not work. And the error is specifically because you are trying to do name/final_strength name is a string, and a comma separated list of things like tou wrote here 'STR', (full_dot * int(strength)),(empty_dot * (10-int(strength))) that becomes a tuple, which is a data type I think is met in the next module of the curriculum
Maybe I’m not understanding what you are saying because I still have errors on the same lines. here is what I did:
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
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 not isinstance(intelligence,int) or not isinstance(charisma,int):
return('All stats should be integers')
if strength < 1 or intelligence < 1 or charisma < 1:
return('All stats should be no less than 1')
if strength > 4 or intelligence > 4 or charisma > 4:
return('All stats should be no more than 4')
total=strength + intelligence + charisma
if total != 7:
return('The character should start with 7 points')
final_strength = 'STR' + '' + str(full_dot * int(strength)) + str(empty_dot * (10-int(strength)))
final_intelligence = 'INT' + '' + str(full_dot * int(intelligence)) + str(empty_dot * (10-int(intelligence)))
final_charisma = 'CHA' + '' + str(full_dot * int(charisma)) + str(empty_dot * (10-int(charisma)))
return(name/'n'(final_strength)/'n'(final_intelligence)/'n'(final_charisma))
no, / is the division operator, the one you use to divide numbers, like 6 / 2 gives 3
are you maybe thinking of \n? this is the code that inside a string means going to a new line, it’s used for example in test 12 to show a multiline string in compact form
If I take the commas out it gives an error messages saying, did you maybe forget to put commas. leave the commas in and it out puts wrong.
I just don’t get it
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
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 not isinstance(intelligence,int) or not isinstance(charisma,int):
return('All stats should be integers')
if strength < 1 or intelligence < 1 or charisma < 1:
return('All stats should be no less than 1')
if strength > 4 or intelligence > 4 or charisma > 4:
return('All stats should be no more than 4')
total=strength + intelligence + charisma
if total != 7:
return('The character should start with 7 points')
final_strength = 'STR' + '' + str(full_dot * int(strength)) + str(empty_dot * (10-int(strength)))
final_intelligence = 'INT' + '' + str(full_dot * int(intelligence)) + str(empty_dot * (10-int(intelligence)))
final_charisma = 'CHA' + '' + str(full_dot * int(charisma)) + str(empty_dot * (10-int(charisma)))
return(name, '\n', (final_strength), '\n' ,(final_intelligence), '\n' ,(final_charisma))
print(create_character('ren',4,2,1))