0

I'm a total noob when it comes to programming so my question probably has a simple solution.

I'm trying to create a basic program where I input a vegetable and the computer tells me at what temperature and for how long I need to cook it for.

Here's the code I wrote:

veg = input('Which vegetable would you like to roast? ')
if veg == 'bell pepper' or 'zucchini' or 'eggplant':
    print('400 degrees for 20 min.')

if veg == 'broccoli':
    print('400 degrees for 25 min.')

if veg == 'asparagus':
    print('425 degrees for 15 min.')

if veg == 'potato':
    print('400 degrees for 30 min.')

The problem is when I input broccoli, asparagus, or potato, it prints out the right time and temp but it also prints out the first line: "400 degrees for 20 min." I expected it to only print out the requested information.

Help is appreciated!

cambie
  • 3
  • 1
  • I hope those are in fahrenheit , not celsius. I however wouldn't cook vegetables at a temperature higher than 100°C (the boiling point of water, ~210°F) so you can keep their nutriments safe. 80°C (180°F) is nice – Cid Mar 18 '23 at 20:16

1 Answers1

4

you need to edit the first statement to compare veg to the string in each or statement or else or comparing just a string literal will always evaluate to true. Here is the revised code:

if veg == 'bell pepper' or veg == 'zucchini' or veg == 'eggplant':
    print('400 degrees for 20 min.')

Making this change produced the correct results for me.

camdenmcgath
  • 166
  • 1
  • 9