Home > Back-end >  Simple Python vacation script for choosing a destination
Simple Python vacation script for choosing a destination

Time:10-08

I can't figure out how to make this code give me the output I need. It is supposed to ask the user where they want to go on vacation, and then display the location they have chosen.

print("Congratulations! You have won an all-inclusive vacation!"   '\n')
input("Please enter your first and last name"   '\n')
print("Please choose where would you like to go on vacation?"   '\n'
            "A. The Bermuda Triangle"   '\n'
            "B. Space"   '\n'
            "C. Antarctica"   '\n')
def choose_location():
    if choose_location == "A":
        print("You chose The Bermuda Triangle")
    elif choose_location == "B":
        print("You chose Space")
    elif choose_location == "C":
        print("You chose Antarctica")


choose_location()

CodePudding user response:

not sure why you need the function

your code has a few problems.

first, don't use the same function name as the variable name. second, instead of print, it should be input. third, you need to save inputs to variables so you can use them.

but you need to use the input instead of print, and save the input to a variable,

print("Congratulations! You have won an all-inclusive vacation!"   '\n')
name = input("Please enter your first and last name"   '\n')

def choose_location():
    location = input("Please choose where would you like to go on vacation?"   '\n'
                       "A. The Bermuda Triangle"   '\n'
                       "B. Space"   '\n'
                       "C. Antarctica"   '\n')

    if location == "A":
        print("You chose The Bermuda Triangle")
    elif location == "B":
        print("You chose Space")
    elif location == "C":
        print("You chose Antarctica")


choose_location()

or even a version that make-use of the function. Notice that I added .upper() so even if the user enters a small letter it will still work


def choose_location(location):
    location = location.upper()
    if location == "A":
        print("You chose The Bermuda Triangle")
    elif location == "B":
        print("You chose Space")
    elif location == "C":
        print("You chose Antarctica")


print("Congratulations! You have won an all-inclusive vacation!"   '\n')
name = input("Please enter your first and last name"   '\n')
choose_location(input("Please choose where would you like to go on vacation?"   '\n'
                   "A. The Bermuda Triangle"   '\n'
                   "B. Space"   '\n'
                   "C. Antarctica"   '\n'))

  • Related