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
#1
Hi everyone! I encountered this problem and spent hours on trying to resolve it:

The following does run just fine when you enter "eggs", or "cereal" :the contents after "If" get executed without issue. However, After executing the contents after "If", the contents after "Else" get executed too! That is, the sentence "Sorry our auto system does not support this option yet \nPlease ask your waiter directly" always follow, regardless if you enter "eggs", or "cereal" or others.

How come the contents after "If" and "Else" be executed at the same time? Thank you for any insight!! Please see the attached.

Blush
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.")
if 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.")
if 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")
    
Error:
Good morning! What would you like for breakfast? You can have eggs, cereal, fruit or pancakes. Please enter your choice of breakfast from the list: eggs How would you like your eggs? You can have them fried, scrambaled, or boiled. Please enter your choice of eggs from the list: boiled 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 arrive soon. Sorry our auto system does not support this option yet Please ask your waiter directly Enjoy your breakfast

.py   Question.py (Size: 2.42 KB / Downloads: 147)
Reply


Messages In This Thread
A simple "If...Else" question from a beginner - by Serena2022 - Jul-11-2022, 01:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 379 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Simple Question - ' defined as "a". ?' Ryan012 10 1,888 May-27-2023, 06:03 PM
Last Post: Ryan012
  Very simple question about filenames and backslashes! garynewport 4 2,175 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Python Tkinter Simple Multithreading Question AaronCatolico1 5 1,794 Dec-14-2022, 11:35 PM
Last Post: deanhystad
Question Beginner Boolean question [Guessing game] TKB 4 2,496 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Simple arithmetic question ebolisa 5 2,197 Dec-15-2021, 04:56 PM
Last Post: deanhystad
  Simple code question about lambda and tuples JasPyt 7 3,563 Oct-04-2021, 05:18 PM
Last Post: snippsat
Big Grin question about simple algorithm to my problem jamie_01 1 1,764 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  Beginner question NameError amazing_python 6 2,659 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  Beginner question - storing values cybertron2 4 3,364 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