Quiz 1


Written by PIRATE KING

Review

Now, let's test your knowledge with a quiz. In addition to the short reviews at the end of each section, I've compiled 10 comprehensive questions covering all our previous topics. Moving forward, you can expect a larger cumulative quiz like this every few chapters to help lock in your learning. This quiz features a mix of multiple-choice, multiple-selection, true or false, and practical coding exercises. All questions include instant answer keys—even the coding challenges—so you can track your progress in real-time.

1. Which of the following lines is a valid Python comment?

2. Which of the following is NOT a recommended Python coding convention according to Pep 8? Choose all that apply.

3. Python Boolean values must start with lowercase letters (e.g. true, false).

4. Which of the following statements about None in Python is correct?

5. Which escape sequence inserts a tab in a Python string?

6. Which of the following expressions evaluate to True, assuming s = "python programming"?

7. Secret Code Extractor


You are given a secret message: message = "X9-ALABASTA-7Q". Write Python code to:

  1. Use indexing to:
    • Print the first character of the string.
    • Print the last character of the string.
  2. Use slicing to:
    • Extract and print the substring "ALABASTA"
    • Extract and print everything before "ALABASTA" (e.g. "X9-").
    • Extract and print everything after "ALABASTA" (e.g. -7Q).

Expected output:

X
Q
ALABASTA
X9-
-7Q

8. Snack Bill Calculator


Write a Python program that:

  1. Starts with these two statements: price_chips = 2.75, price_juice = 1.40
  2. Use arithmetic operators to:
    • Calculate the total cost of buying 3 bags of chips and 2 bottles of juice.
    • Store it in a variable called total.
  3. Use an augmented assignment operator to:
    • Add a service fee of 0.50 to total in one step (e.g. +=).
  4. Use round to:
    • Round total to 2 decimal places.
  5. Print the result in this format: Final total: $11.55

9. Movie Ticket Price Calculator


Write a program that calculates the ticket price based on the customer's age.

  1. Define a variable age (you can set it directly in code to any number).
  2. Use if, elif, and else statements to decide the ticket price based on this:
    • If the customer is under 5, the price is $0 (free).
    • If the customer is between 5 (inclusive) and 18 (exclusive), the price is $7.
    • If the customer is between 18 (inclusive) and 65 (exclusive), the price is $12.
    • If the customer is 65 or older, price is $8.
  3. Print a message displaying: Your ticket price is $XX. where XX is the price based on age. For example,
    • If age = 20, output: Your ticket price is $12
    • If age = 70, output: Your ticket price is $8

10. Online Store Discount Checker


Write a Python program that determines whether a customer qualifies for an online store discount and calculates the final price.

  1. Variables:
    • customer_name (string), e.g. "Alice"
    • purchase_amount (float), e.g. 120.50
    • is_member (boolean), e.g. True or False
  2. Logic:
    • The base discount is 5% for all customers.
    • Members get an additional 10% discount if their purchase amount is over $100.
    • If the purchase amount is less than $20, no discount is applied regardless of membership.
  3. Use string indexing and slicing to:
    • Extract and print the first 3 letters of customer_name in uppercase as Customer code: XYZ.
  4. Use arithmetic operators and assignment to:
    • Calculate the final price after discount.
    • Round the final price to 2 decimal places.
  5. Print a summary message using a formatted string:
Customer code: ALI
Original purchase: $120.51
Member discount applied: True
Final price: $102.43
© PIRATE KING 2025
GOLDSTONE STUDIO LLC
Privacy Policy