Practice Exercises
Practice what you’ve learned so far.
We'll cover the following...
Let's see what you’ve learned so far with a quiz. Let's begin!
Quiz yourself!
Variables and built-in functions
Consider the following Python code snippet:
num1 = 5
num2 = 8
num2 = num1
print("The value of num2 is:", num2)
What is the final value of variable num2?
10
8
5
None of the above
A quick knowledge test
Question: Imagine you want to write a Python program that calculates and displays the total number of items in a shopping cart, which is given as an integer. Which of these functions (print(), input(), str()) would you use to display this number in a sentence, and why?
Exercise—Placing order in a restaurant
Let's create a program that acts as an e-waiter. The program should be able to do the following:
Greet the user by welcoming them to their restaurant and asking for the user’s name.
Prompt the user to choose from starters, main menu, and dessert respectively.
Take their name and repeat their order for confirmation.
To get you started, we have already added partial code for you in the widget below. Go ahead and add the rest of the code to complete our program.
print("Welcome to Our Restaurant!")
name = input("May I have your name, please? ")
print("Hello", name, "! Here is our menu:")
print("In starters, we have some suggestions: ")
print("Soup, Salad, Garlic Bread")
print() # for new line
order_starters = input("What would you like for starter? ")
# Add code for the main menu here. Main menu item suggestions include: Steak, Pasta, Burger
print() # for new line
# Add code for dessert here. Dessert item suggestions include: Cake, Ice Cream, Fruit Salad
print() # for new line
# Add code for order confirmation here. The output could look like this:
# Thank you Sara ! I'm repeating your order:
# Salad for starters
# Pasta for main menu
# Cake for dessert