Skip to content

Practical Exam Review

This exam component will be completed on the computer. You may use the following for reference:

Review Question 1 — Unit 1 Practice (Input, Arithmetic, Conditionals)

Write a Python program called movie_ticket.py that calculates the cost of movie tickets.

  1. Prompt the user for:

    • Number of adult tickets (integer)
    • Number of child tickets (integer)
  2. Use the following prices:

    • Adult ticket → $14.50
    • Child ticket → $9.75
  3. Calculate and print:

    • The subtotal
    • HST (13%)
    • The final total cost
  4. Use if statements to display one of the following messages:

    • If the total cost is $100 or moreLarge purchase!
    • Otherwise → Thank you for your purchase!
  5. Round all dollar amounts to two decimal places.

Example Output

Enter number of adult tickets: 4
Enter number of child tickets: 3

Subtotal: $90.25
HST: $11.73
Total: $101.98
Large purchase!

Review Question 2 — Unit 3 Practice (Strings, Lists, Loops, Functions)

Write a Python program called name_analyzer.py that works with a list of names.

  1. Prompt the user to enter five names, one at a time, and store them in a list.

  2. Print:

    • The full list of names
    • The total number of characters across all names (excluding spaces)
  3. Define and use the following functions:

    • count_long_names(names)

      • Given a list of names, returns how many names have more than 5 characters.
    • longest_name(names)

      • Given a list of names, returns the longest name in the list.
      • If there is a tie, return the either one.
  4. Use loops to process the list (do not hard-code indices).

Example Output

Enter name 1: George
Enter name 2: Samantha
Enter name 3: Jordan
Enter name 4: Lee
Enter name 5: Christopher

Names: ['George', 'Samantha', 'Jordan', 'Lee', 'Christopher']
Total characters (no spaces): 34
Number of long names: 4
Longest name: Christopher

Starter Code

You might find it useful to start with the code below:

# Add the two functions here:
def count_long_names(names):
    long_name_count = 0

    # Add code here that will go through the names and update
    # long_name_count as necessary

    return long_name_count

# Code to read in the list of names
names = []
for i in range(5):
    name = input(f"Enter name {i + 1}: ")
    names.append(name)

# Add the remaining code here
print(f"Total number of long names: {count_long_names(name)}")
Click to reveal answers
# QUESTION 1
adult_tickets = int(input("How many adult tickets? "))
child_tickets = int(input("How many child tickets? "))

subtotal = adult_tickets * 14.50 + child_tickets * 9.75
tax = subtotal * 0.13
final = subtotal + tax

print(f"The subtotal is ${subtotal}")
print(f"The tax is ${round(tax, 2)}")
print(f"The total is ${round(final, 2)}")

if final >= 100:
    print("Large purchase!")
else:
    print("Thank you for your purchase!")


###################################################################

# QUESTION 2
# Add the two functions here:
def count_long_names(names):
    long_name_count = 0

    # Add code here that will go through the names and update
    # long_name_count as necessary
    for name in names:
        if len(name) > 5:
            long_name_count += 1

    return long_name_count

def longest_name(names):
    longest = ""
    longest_length = 0

    for name in names:
        if len(name) > longest_length:
            longest = name
            longest_length = len(name)

    return longest

# Code to read in the list of names
names = []
for i in range(5):
    name = input(f"Enter name {i + 1}: ")
    names.append(name)

# Add the remaining code here
print(names)

num_chars = 0
for name in names:
    num_chars += len(name)

print(f"Total characters (no spaces): {num_chars}")

print(f"Total number of long names: {count_long_names(names)}")

print(f"Longest name: {longest_name(names)}")