Practice Exercises

Practice what you’ve learned so far.

Let's see what you’ve learned so far with a quiz. Let's begin!

Quiz yourself!

Variables and built-in functions

1.

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?

A.

10

B.

8

C.

5

D.

None of the above


1 / 3

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?

Saved

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:

  1. Greet the user by welcoming them to their restaurant and asking for the user’s name.

  2. Prompt the user to choose from starters, main menu, and dessert respectively.

  3. 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
E-waiter program
Show Solution