More Practice with Python Variables, Conditions and User Input

In this activity, you will get more practice declaring and manipulating variables, using conditionals, and requesting user input.

Starter file

# Declare a variable `welcome_name` as an input with a string of "Welcome to the sandwich shop, what do I call you? ".


# Then print the string "Hello" concatenated with the variable `welcome_name`.


# Declare a variable `question_sandwich` as an input with a string of "Are you here for a sandwich? (Yes or No?) ".


# If `question_sandwich` is equal to true declare a variable `food_prompt` as an input with a string of "What kind of sandwich would you like?".
# Then print a string of "Please wait 10 min for your " concatenated with the variable `food_prompt`.
# Else If `question_sandwich` is false, print a string of "If you don't want a sandwich what are you here for?!".
# Else print a string of "You did not write Yes or No!"

Instructions

Open the starter file and perform the following:

  1. Declare a variable welcome_name as an input with a string of “Welcome to the sandwich shop, what do I call you?”
  2. Print the string “Hello” concatenated with the variable welcome_name.
  3. Declare a variable question_sandwich as an input with a string of “Are you here for a sandwich? Yes or No?”
  4. If question_sandwich is equal to true:
    • Declare a variable food_prompt as an input with a string of “What kind of sandwich would you like?”
    • Print a string of “Please wait 10 min for your ” concatenated with the variable food_prompt.
    • If question_sandwich is false, print a string of “If you don’t want a sandwich, what are you here for?!”

Solution

# Declare a variable `welcome_name` as an input with a string of "Welcome to the sandwich shop, what do I call you?".
welcome_name = input("Welcome to the sandwich shop, what do I call you? ")

# Then print the string "Hello" concatenated with the variable `welcome_name`.
print(f"Hello {welcome_name}")

# Declare a variable `question_sandwich` as an input with a string of "Are you here for a sandwich?".
question_sandwich = input("Are you here for a sandwich? Yes or No?")

# If `question_sandwich` is equal to true declare a variable `food_prompt` as an input with a string of "What kind of sandwich would you like?".
# Then print a string of "Please wait 10 min for your " concatenated with the variable `food_prompt`.
# Else If `question_sandwich` is false, print a string of "If you don't want a sandwich what are you here for?!".
# Else print a string of "You did not write Yes or No!"
if question_sandwich == "Yes":
    food_prompt = input("What kind of sandwich would you like?")
    print(f"Please wait 10 mins for your {food_prompt}")
elif question_sandwich == "No":
    print("If you don't want a sandwich what are you here for?!")
else:
    print("You did not write Yes or No!")

We will be happy to hear your thoughts

Leave a reply