I need to write a program that asks for a cheese and checks if the cheese is in the list. If the cheese is in the list, it should print, for example:
Cheese: Haloumi
Haloumi is a cheese!
If the cheese isn't in the list it should print:
Cheese: Pita
Pita might not be a cheese.
[CODE lang="python" title="F-string Problem"]cheeses = ['Cheddar', 'Bocconcini', 'Haloumi', 'Paneer', 'Gorgonzola', 'Mozzarella', 'Parmesan', 'Brie', 'Gruyere']
# Add your code after this.
x = input("Cheese: ")
if "Cheddar" in cheeses:
print(f"{x} is a cheese!")
else:
print(f"{x} might not be a cheese.")[/CODE]
For some reason, the "else:" section doesn't run properly and I don't know why.
Cheese: Haloumi
Haloumi is a cheese!
If the cheese isn't in the list it should print:
Cheese: Pita
Pita might not be a cheese.
[CODE lang="python" title="F-string Problem"]cheeses = ['Cheddar', 'Bocconcini', 'Haloumi', 'Paneer', 'Gorgonzola', 'Mozzarella', 'Parmesan', 'Brie', 'Gruyere']
# Add your code after this.
x = input("Cheese: ")
if "Cheddar" in cheeses:
print(f"{x} is a cheese!")
else:
print(f"{x} might not be a cheese.")[/CODE]
For some reason, the "else:" section doesn't run properly and I don't know why.