KOTZ
KOTZ

Reputation: 145

How to use an if statment to respond to several different string options

I'm making a pizzeria experience in python and I'm having some trouble because I'm wondering how to add several string options to an if statement.

Here is the code I'm trying to run:

menu = ("    Happy Ham's Pizza Hut \n\nSIZES \nLarge pizza (20in.) \nMedium pizza (15in.) \nSmall pizza (personel 10in.)\n")
menu += ("\nTYPES \nVegan pizza(non-dairy cheese, tofu pepporoni)\nVegatarian pizza(ground-corn crust, graded radish cheese alternative, cucumber rounds)")
name = str(input(" \n Hello, and welcome to happy ham's pizza hut! \nWould you like a menu? \n >>"))
if name == ('yes, yes please'):
    print(menu)

Now the problem is when making the if statement I want it to have the same response for several different answers. How do I do that?

Upvotes: 0

Views: 65

Answers (2)

Isaiah Guillory
Isaiah Guillory

Reputation: 107

Here is the entire fixed code

menu = ("Happy Ham's Pizza Hut \n\nSIZES \nLarge pizza (20in.) \nMedium pizza 
       (15in.) \nSmall pizza (personel 10in.)\n")
menu += ("\nTYPES \nVegan pizza(non-dairy cheese, tofu pepporoni)\nVegatarian 
        pizza(ground-corn crust, graded radish cheese alternative, cucumber 
        rounds)")
name = str(input(" \n Hello, and welcome to happy ham's pizza hut! \nWould you 
       like a menu? \n >>"))

if name in ('yes', 'yes please'):
   print(menu)
else:
   print("Customer doesn't want to see menu")

Upvotes: 2

Data_Is_Everything
Data_Is_Everything

Reputation: 2017

Just a couple of changes, everything looks good.

menu = ("Happy Ham's Pizza Hut \n\nSIZES \nLarge pizza (20in.) \nMedium pizza 
       (15in.) \nSmall pizza (personel 10in.)\n")
menu += ("\nTYPES \nVegan pizza(non-dairy cheese, tofu pepporoni)\nVegatarian 
        pizza(ground-corn crust, graded radish cheese alternative, cucumber 
        rounds)")
name = str(input(" \n Hello, and welcome to happy ham's pizza hut! \nWould you 
       like a menu? \n >>"))

acceptableresponses = ["yes", "yes please", "YES!"]
### create a list of acceptable responses to display the menu.

if name in acceptableresponses:
   print(menu)
else:
   print("Customer doesn't want to see menu")

### else case doesn't show menu rather prints a msg saying user doesn't want to see the menu since user input something other than what's in the list declared.

Upvotes: 2

Related Questions