jramone
jramone

Reputation: 11

Design a program that displays the following menu: Select a language and I Will Say Good Morning 1. English 2. Italian 3. Spanish 4. German 5

This is what I have so far. I am not getting any errors but also is giving me a blank shell.

Design a program that displays the following menu:

Select a language and I Will Say Good Morning

1. English
2. Italian
3. Spanish
4. German

5. End the Program

Enter your selection#  

This is my code:

def mainMenu():
            print("1. English")
            print("2. Italian")
            print("3. Spanish")
            print("4. German")
            print("5. Quit")
            while True:
                try:
                    selection==int(input("Enter a choice: "))
                    if selection==1:
                        goodmorning()
                        break
                    elif selection==2:
                        buongiorno()
                        break
                    elif selection==3:
                        buenosdias()
                        break
                    elif selection==4:
                        gutenmorgen()
                        break
                    elif selection==5:
                        break
                    else:
                        print("Invalid choice. Enter 1-5.")
                except ValueError:
                    print("Invalid choice! Choose 1-5!!")
            exit 
    def goodmorning():
         print("Good Morning")
         anykey=input("Enter anything to return to the Main Menu")
         mainMenu()
    def buongiorno():
         print("Buongiorno")
         anykey=input("Enter anything to return to the Main Menu")
         mainMenu()
    def buenosdias():
         print("Buenos Dias")
         anykey=input("Enter anything to return to the Main Menu")
         mainMenu()
    def gutenmorgen():
         print("Guten morgen")
         anykey=input("Enter anything to return to the Main Menu")
         mainMenu()

Upvotes: 1

Views: 461

Answers (1)

qwerteee
qwerteee

Reputation: 307

There are two problems with this:

1: You haven't actually run the mainMenu() function, you've just defined it. To fix this simply add mainMenu() on the very bottom of your code.

2: Once you have done this, there is still another error in the selection==int(input("Enter a choice: ")) line. You only need one =, like this: selection=int(input("Enter a choice: "))

Find the updated code below:

def mainMenu():
    print("1. English")
    print("2. Italian")
    print("3. Spanish")
    print("4. German")
    print("5. Quit")
    while True:
        try:
            selection = int(input("Enter a choice: "))
            if selection == 1:
                goodmorning()
                break
            elif selection == 2:
                buongiorno()
                break
            elif selection == 3:
                buenosdias()
                break
            elif selection == 4:
                gutenmorgen()
                break
            elif selection == 5:
                break
            else:
                print("Invalid choice. Enter 1-5.")
        except ValueError:
            print("Invalid choice! Choose 1-5!!")
    exit


def goodmorning():
    print("Good Morning")
    anykey = input("Enter anything to return to the Main Menu")
    mainMenu()


def buongiorno():
    print("Buongiorno")
    anykey = input("Enter anything to return to the Main Menu")
    mainMenu()


def buenosdias():
    print("Buenos Dias")
    anykey = input("Enter anything to return to the Main Menu")
    mainMenu()


def gutenmorgen():
    print("Guten morgen")
    anykey = input("Enter anything to return to the Main Menu ")
    mainMenu()

mainMenu()

Upvotes: 1

Related Questions