I could use some support, can’t get past set #7 as I have no idea how to do what it’s asking. When I check others work I see everyone is using language that hasn’t been taught yet!
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'
print(create_character('',1,2,3))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
yes, I’m fully aware of how to check, it’s literally in my code above. I’m not asking for the solution, I’m asking how I’m supposed to complete the project using only the code taught up to this point.
Please post the actual code instead of a picture, and I cannot run the code in your picture.
That works, but ideally we should be able to handle this in one elif. What did the earlier lessons say was a way to check if one of two logical conditions was true?
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 isinstance(strength, int) or isinstance(intelligence, int) or isinstance(charisma, int) == Flase:
return 'almost there'
else:
return 'Good to go'
#if not isinstance(strength, int):
# if intelligence and charisma == int:
# return 'This shit worked'
#if not isinstance(strength, int):
# return 'All stats should be integers'
#elif not isinstance(intelligence, int):
# return 'All stats should be integers'
#elif not isinstance(charisma, int):
# return 'All stats should be integers'
print(create_character('zac',4,3,4))
The or operator separates logically independent statements. So (full statement 1) or (full statement 2). That doesn’t appear to be what you’re attempting though. (You can always use ( ) around each part of the or to clearly logically group the independent statements).
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 isinstance(strength, int) != (isinstance(intelligence, int) and isinstance(charisma, int)):
return 'All stats should be integers'
else:
return 'ints check out'
print(create_character('Zac',2,3,4))
Like I said, you need three independent checks. You have those above in separate elifs. Each of those checks is right. They can be linked with ors as long as the checks stay separate. You use ( ) to keep the checks separate.
Think about the logical statements you’re making in English.
What you want is this:
IF strength is an int AND intelligence is an int AND charisma is an int, THEN they are all int and we are good. OTHERWISE return an error.
In your first attempt, you used not which is also fine. Just know you are checking the opposite:
IF strength is NOT and int OR intelligence is NOT an int THEN return an error.