Python Forum
A simple "If...Else" question from a beginner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A simple "If...Else" question from a beginner
#2
if you do not want the else to execute change all other if's except first to elif. the else only works with last if.

print("Good morning! What would you like for breakfast? \nYou can have eggs, cereal, fruit or pancakes.")

breakfast = input("Please enter your choice of breakfast from the list: ")

if breakfast == "eggs":
    print("How would you like your eggs? \nYou can have them fried, scrambaled, or boiled.")

    eggstype = input ("Please enter your choice of eggs from the list: ")
    if eggstype == "boiled":
        print("How would you like your eggs boiled? \nYou can have them hard or soft.")

        boiledtype=input("Please enter hard or soft: ")
        if boiledtype == "hard":
            print ("Thank you! Your hard boiled eggs will arrive soon.")
        if boiledtype == "soft":
            print ("Thank you! Your soft boiled eggs will arrive soon.")
    else:
        print("Sorry your choice is not available.")
elif breakfast=="cereal":
    print("What gype of cereal would you like? \nYou may choose porridge, muesli, corn flakes or rice bubbles.")
    cerealtype = input("Pleaes enter your choice of cereals from the list: ")
    if cerealtype == "porridge":
        print("What type of milk you'd like with your cereal? \nYou may have full cream milk or light white milk.")

        milktype = input("Please enter full cream milk or light white milk:")
        if milktype == "full cream milk":
             print("Thank you and your porridge with full cream milk will arrive shortly.")
        if milktype == "light white milk":
            print("Thank you and your porridge with light white milk will arrive shortly.")
    else:
        print("Sorry your choice is not available.")
elif breakfast=="fruit":
    print("What type of fruit would you like? \nYou may choose tropical or European fruit.")
    fruittype = input("Please enter your choice of fruit:")
    if fruittype == "tropical":
        print("What type of tropical fruit would you like? \nYou may choose duriam or pineapple.")

        tropicaltype = input("Please enter duriam or pineapple.")
        if tropicaltype == "duriam":
            print("Thank you and your duriam will arrive shortly.")
        if tropicaltype == "pineapple":
            print("Thank you and your pineapple will arrive shortly.")
    else:
        print("Sorry your choice is not available.")


else:
    print("Sorry our auto system does not support this option yet \nPlease ask your waiter directly")
print("Enjoy your breakfast")
Output:
λ python play.py Good morning! What would you like for You can have eggs, cereal, fruit or p Please enter your choice of breakfast How would you like your eggs? You can have them fried, scrambaled, Please enter your choice of eggs from How would you like your eggs boiled? You can have them hard or soft. Please enter hard or soft: soft Thank you! Your soft boiled eggs will Enjoy your breakfast
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: A simple "If...Else" question from a beginner - by menator01 - Jul-11-2022, 02:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 219 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Simple Question - ' defined as "a". ?' Ryan012 10 1,684 May-27-2023, 06:03 PM
Last Post: Ryan012
  Very simple question about filenames and backslashes! garynewport 4 2,011 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Python Tkinter Simple Multithreading Question AaronCatolico1 5 1,628 Dec-14-2022, 11:35 PM
Last Post: deanhystad
Question Beginner Boolean question [Guessing game] TKB 4 2,368 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Simple arithmetic question ebolisa 5 2,109 Dec-15-2021, 04:56 PM
Last Post: deanhystad
  Simple code question about lambda and tuples JasPyt 7 3,396 Oct-04-2021, 05:18 PM
Last Post: snippsat
Big Grin question about simple algorithm to my problem jamie_01 1 1,704 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  Beginner question NameError amazing_python 6 2,509 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  Beginner question - storing values cybertron2 4 3,272 Mar-09-2021, 04:21 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020