Reputation: 38
I have the code below so far to make an outfit checker and IDLE says that the double quotations marks at the end of each print statement are an invalid syntax. I don't know how it's wrong. Can anyone help me? Thanks in advance!
#Outfit Checker
cher_dress_color = 'pink'
cher_shoe_color = 'white'
cher_has_earrings = True
dionne_dress_color = 'purple'
dionne_shoe_color = 'pink'
dionne_has_earrings = True
#Cher and Dionne have different dress colors
print(f "Both girls have different dress colors? {cher_dress_color != 'purple' and dionne_dress_color != 'pink'}")
#Cher and Dionne are both wearing earrings
print(f "Both girls are wearing earrings? {cher_has_earrings == True and dionne_has_earrings == True}")
#At least one person is wearing pink
print(f "At least one person is wearing pink? {cher_dress_color =='pink' or dionne_dress_color =='pink'}")
#No one is wearing green
print(f "No one is wearing green? {cher_dress_color != 'green' or dionne_dress_color != 'green'}")
#Cher and Dionne have the same shoe color
print(f "Both girls have the same shoe colors? {cher_shoe_color == 'pink' or dionne_shoe_color == 'pink') or (cher_shoe_color == 'white' or dionne_shoe_color == 'white')}")
Upvotes: 0
Views: 54
Reputation: 32921
Mayur's answer explains the problem and how to fix it, but actually you don't even need f-strings here, plus you can simplify the logic.
In the last line, I think you meant to use (and) or (and)
instead of (or) or (or)
.
print("Both girls have different dress colors?", cher_dress_color != dionne_dress_color)
print("Both girls are wearing earrings?", cher_has_earrings and dionne_has_earrings)
dress_colors = [cher_dress_color, dionne_dress_color]
print("At least one person is wearing pink?", 'pink' in dress_colors)
print("No one is wearing green?", 'green' not in dress_colors)
print("Both girls have the same shoe colors?", cher_shoe_color == dionne_shoe_color)
Output:
Both girls have different dress colors? True
Both girls are wearing earrings? True
At least one person is wearing pink? True
No one is wearing green? True
Both girls have the same shoe colors? False
Upvotes: 2
Reputation: 1082
You have added extra space between f
and your string
but it should be like this
print(f"Both girls have different dress colors? {cher_dress_color != 'purple' and dionne_dress_color != 'pink'}")
not like this
print(f "Both girls have different dress colors? {cher_dress_color != 'purple' and dionne_dress_color != 'pink'}")
and also you forget to add parenthesis in the last print statement print(f"Both girls have the same shoe colors? {(or)or(or)}
here is final fixed code
cher_dress_color = 'pink'
cher_shoe_color = 'white'
cher_has_earrings = True
dionne_dress_color = 'purple'
dionne_shoe_color = 'pink'
dionne_has_earrings = True
#Cher and Dionne have different dress colors
print(f"Both girls have different dress colors? {cher_dress_color != 'purple' and dionne_dress_color != 'pink'}")
#Cher and Dionne are both wearing earrings
print(f"Both girls are wearing earrings? {cher_has_earrings == True and dionne_has_earrings == True}")
#At least one person is wearing pink
print(f"At least one person is wearing pink? {cher_dress_color =='pink' or dionne_dress_color =='pink'}")
#No one is wearing green
print(f"No one is wearing green? {cher_dress_color != 'green' or dionne_dress_color != 'green'}")
#Cher and Dionne have the same shoe color
print(f"Both girls have the same shoe colors? {(cher_shoe_color == 'pink' or dionne_shoe_color == 'pink') or (cher_shoe_color == 'white' or dionne_shoe_color == 'white')}")
output
Both girls have different dress colors? True
Both girls are wearing earrings? True
At least one person is wearing pink? True
No one is wearing green? True
Both girls have the same shoe colors? True
Upvotes: 1