From ba361e5475bffc0370d2785e0432b0eb3e1317b6 Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Tue, 27 Jan 2026 20:26:25 +0530 Subject: [PATCH] feat(curriculum): add Movie Ticket Booking Calculator workshop to Python cert (#64866) --- client/i18n/locales/english/intro.json | 6 + .../index.md | 9 + .../694a9ff65d4472dd451d8255.md | 61 +++++++ .../694cc1b515976889afd4cded.md | 60 +++++++ .../6958dd85587e10c99162dd81.md | 71 ++++++++ .../6958de0d773289a89515a6b8.md | 55 ++++++ .../6958dfa0c74b237e1b56ce04.md | 54 ++++++ .../6958e0ecc121b0ae3dd9c5e0.md | 80 +++++++++ .../6958e1875e592b58e8852757.md | 93 +++++++++++ .../6958e2377cacbc46a7f7383a.md | 80 +++++++++ .../6958e59845777391b86d7331.md | 115 +++++++++++++ .../6958ea03cb1c4684c138754a.md | 156 ++++++++++++++++++ .../696099abb6acc539b27055a1.md | 55 ++++++ .../696099c1ac72a4e585de1d5b.md | 67 ++++++++ .../6960a5165f7efe52a0c0aa39.md | 62 +++++++ .../6960a848aacf859f7bb15447.md | 54 ++++++ .../6960b308bf41cc39c9b4b438.md | 67 ++++++++ .../6960b6a6ea06e27dcc7eef37.md | 95 +++++++++++ .../6960b8632b9544d1f57295f4.md | 70 ++++++++ .../6960ba6e6c95ed4ad896c6f2.md | 77 +++++++++ .../696cb889fc4fdeb337e52864.md | 76 +++++++++ .../696cbb3985e23420cd45c58f.md | 119 +++++++++++++ .../6970f09b547e10402abf2847.md | 79 +++++++++ ...kshop-movie-ticket-booking-calculator.json | 33 ++++ .../structure/superblocks/python-v9.json | 1 + 25 files changed, 1695 insertions(+) create mode 100644 client/src/pages/learn/python-v9/workshop-movie-ticket-booking-calculator/index.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694a9ff65d4472dd451d8255.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694cc1b515976889afd4cded.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dd85587e10c99162dd81.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958de0d773289a89515a6b8.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dfa0c74b237e1b56ce04.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e0ecc121b0ae3dd9c5e0.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e1875e592b58e8852757.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e2377cacbc46a7f7383a.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e59845777391b86d7331.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958ea03cb1c4684c138754a.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099abb6acc539b27055a1.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099c1ac72a4e585de1d5b.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a5165f7efe52a0c0aa39.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a848aacf859f7bb15447.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b308bf41cc39c9b4b438.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b6a6ea06e27dcc7eef37.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b8632b9544d1f57295f4.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960ba6e6c95ed4ad896c6f2.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cb889fc4fdeb337e52864.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cbb3985e23420cd45c58f.md create mode 100644 curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6970f09b547e10402abf2847.md create mode 100644 curriculum/structure/blocks/workshop-movie-ticket-booking-calculator.json diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 769cd1fe435..734a3b0dc4a 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -6957,6 +6957,12 @@ "In these lessons, you will learn about booleans and conditionals in Python." ] }, + "workshop-movie-ticket-booking-calculator": { + "title": "Build a Movie Ticket Booking Calculator", + "intro": [ + "In this workshop, you will practice how to use booleans and conditional statements in Python by building a movie ticket booking calculator." + ] + }, "lecture-understanding-functions-and-scope": { "title": "Understanding Functions and Scope", "intro": [ diff --git a/client/src/pages/learn/python-v9/workshop-movie-ticket-booking-calculator/index.md b/client/src/pages/learn/python-v9/workshop-movie-ticket-booking-calculator/index.md new file mode 100644 index 00000000000..01d1b2d6a48 --- /dev/null +++ b/client/src/pages/learn/python-v9/workshop-movie-ticket-booking-calculator/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Build a Movie Ticket Booking Calculator +block: workshop-movie-ticket-booking-calculator +superBlock: python-v9 +--- + +## Introduction to the Build a Movie Ticket Booking Calculator + +In this workshop, you will practice how to use booleans and conditional statements in Python by building a movie ticket booking calculator. diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694a9ff65d4472dd451d8255.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694a9ff65d4472dd451d8255.md new file mode 100644 index 00000000000..fd02d7bfdf2 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694a9ff65d4472dd451d8255.md @@ -0,0 +1,61 @@ +--- +id: 694a9ff65d4472dd451d8255 +title: Step 1 +challengeType: 20 +dashedName: step-1 +--- + +# --description-- + +In this workshop, you will practice how to use booleans and conditional statements in Python by building a movie ticket booking calculator. + +Begin by declaring variables that store information about the user and the movie show. + +As you learned in previous lessons, variables are assigned using the assignment operator (`=`) this way: + +```py +# Assigns the value 10 to variable x +x = 10 +``` + +Create a variable named `base_price` to store the base price of the movie ticket and set its value to `15`. Create another variable named `age` to store the user's age and set its value to `21`. + +# --hints-- + +You should declare a variable named `base_price`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("base_price")`)) }) +``` + +You should assign the integer value `15` to `base_price`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("base_price").is_equivalent("base_price = 15") +`)) }) +``` + +You should declare a variable named `age`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("age")`)) }) +``` + +You should assign the integer value `21` to `age`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("age").is_equivalent("age = 21") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694cc1b515976889afd4cded.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694cc1b515976889afd4cded.md new file mode 100644 index 00000000000..f155a565995 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/694cc1b515976889afd4cded.md @@ -0,0 +1,60 @@ +--- +id: 694cc1b515976889afd4cded +title: Step 2 +challengeType: 20 +dashedName: step-2 +--- + +# --description-- + +Now you need to store some string values about the movie ticket. You can store strings in Python this way: + +```py +name = 'Alice' +``` + +Create a variable named `seat_type` to store the type of seat the user has selected and set its value to the string `Gold`. Create another variable named `show_time` to store the show time of the movie and set its value to the string `Evening`. + +Remember to surround both values with either single or double quotes. + +# --hints-- + +You should declare a variable named `seat_type`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("seat_type")`)) }) +``` + +You should assign the string `Gold` to `seat_type`. Remember to surround the value with either single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("seat_type").is_equivalent("seat_type = 'Gold'") +`)) }) +``` + +You should declare a variable named `show_time`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("show_time")`)) }) +``` + +You should assign the string `Evening` to `show_time`. Remember to surround the value with either single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("show_time").is_equivalent("show_time = 'Evening'") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dd85587e10c99162dd81.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dd85587e10c99162dd81.md new file mode 100644 index 00000000000..777046f0835 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dd85587e10c99162dd81.md @@ -0,0 +1,71 @@ +--- +id: 6958dd85587e10c99162dd81 +title: Step 3 +challengeType: 20 +dashedName: step-3 +--- + +# --description-- + +As you learned in previous lessons, in Python, an `if` statement can be used to run code depending on if a condition is true. + +An `if` statement consists of the `if` keyword, followed by a condition and a colon. The code to run when the condition is true, which must be indented, is called the body of the `if` statement. + +```py +if condition: + # Code to execute if condition is True +``` + +In this step, you will check if the user is eligible to book a movie ticket based on their age. + +Create an `if` statement to check if `age` is greater than `17`. Inside the body of the `if` statement, print `User is eligible to book a ticket`. This will print the message only when the user's age is greater than `17`. + +Remember to indent the body of the `if` statement and surround the message with single or double quotes inside the `print()` call. + +# --hints-- + +You should have an `if` statement. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[0]`)) }) +``` + +The `if` statement condition should be `age > 17`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[0].find_conditions()[0] +assert _cond.is_equivalent("age > 17") or _cond.is_equivalent("17 < age") +`)) }) +``` + +You should have a `print()` call inside your `if` statement. Remember to indent the body of the `if` statement. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[0].find_bodies()[0].find_calls("print")[0] +`)) }) +``` + +You should print `User is eligible to book a ticket` inside your `if` statement. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[0].find_bodies()[0].has_call("print('User is eligible to book a ticket')") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958de0d773289a89515a6b8.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958de0d773289a89515a6b8.md new file mode 100644 index 00000000000..e113573db7f --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958de0d773289a89515a6b8.md @@ -0,0 +1,55 @@ +--- +id: 6958de0d773289a89515a6b8 +title: Step 4 +challengeType: 20 +dashedName: step-4 +--- + +# --description-- + +Now you will check whether the user is allowed to book an evening show based on their age. + +Create an `if` statement to check if `age` is greater than or equal to `21`. Inside the body of the `if` statement, print `User is eligible for Evening shows`. + +# --hints-- + +You should have two `if` statements in your code. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[1]`)) }) +``` + +Your second `if` statement condition should be `age >= 21`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[1].find_conditions()[0] +assert _cond.is_equivalent("age >= 21") or _cond.is_equivalent("21 <= age") +`)) }) +``` + +You should print `User is eligible for Evening shows` inside your new `if` statement. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[1].find_bodies()[0].has_call("print('User is eligible for Evening shows')") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dfa0c74b237e1b56ce04.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dfa0c74b237e1b56ce04.md new file mode 100644 index 00000000000..5f4645a5941 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958dfa0c74b237e1b56ce04.md @@ -0,0 +1,54 @@ +--- +id: 6958dfa0c74b237e1b56ce04 +title: Step 7 +challengeType: 20 +dashedName: step-7 +--- + +# --description-- + +The user qualifies for a membership discount if they are a member. + +Create a variable named `discount` and set its value to `0`. This will store the discount the user gets on the movie ticket. + +# --hints-- + +You should declare a variable named `discount`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("discount")`)) }) +``` + +You should assign the integer value `0` to `discount`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("discount").is_equivalent("discount = 0") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = True +is_weekend = False + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e0ecc121b0ae3dd9c5e0.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e0ecc121b0ae3dd9c5e0.md new file mode 100644 index 00000000000..e7d05db8ff5 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e0ecc121b0ae3dd9c5e0.md @@ -0,0 +1,80 @@ +--- +id: 6958e0ecc121b0ae3dd9c5e0 +title: Step 9 +challengeType: 20 +dashedName: step-9 +--- + +# --description-- + +You should also handle the case when the user does not qualify for a membership discount. + +Add an `else` clause to your `if` statement and print `User does not qualify for membership discount` inside the `else` body. + +You can print a message followed by a variable like this: + +```py +print('Total:', total) +``` + +You also want to display the updated value of `discount`. Below the `if...else` statement, use the `print()` call to display a message that shows `Discount:` followed by the updated value of `discount`. Then, check the output in the terminal. + +# --hints-- + +You should have an `else` clause. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[2].find_conditions()[1].is_empty()`)) }) +``` + +You should print `User does not qualify for membership discount` inside your `else` clause. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[2].find_bodies()[1].has_call("print('User does not qualify for membership discount')") +`)) }) +``` + +You should have `print('Discount:', discount)` below your `if...else` statement. + +```js +({ test: () => (runPython(` +if_stmt = """if is_member: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount')""" +print_call = "print('Discount:', discount)" +assert _Node(_code).is_ordered(if_stmt, print_call) +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = True +is_weekend = False + +discount = 0 +if is_member: + discount = 3 + print('User qualifies for membership discount') +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e1875e592b58e8852757.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e1875e592b58e8852757.md new file mode 100644 index 00000000000..f46997c7b75 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e1875e592b58e8852757.md @@ -0,0 +1,93 @@ +--- +id: 6958e1875e592b58e8852757 +title: Step 12 +challengeType: 20 +dashedName: step-12 +--- + +# --description-- + +Now create a variable named `extra_charges` and set it to `0`. This will represent extra charges to apply to the movie ticket on weekends. + +Then, create an `if` statement to check if `is_weekend` is truthy. Inside the body of `if` statement, update the `extra_charges` value to `2` and print `Extra charges will be applied` in the terminal. + +# --hints-- + +You should declare a variable named `extra_charges`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("extra_charges")`)) }) +``` + +You should assign the integer value `0` to `extra_charges`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("extra_charges").is_equivalent("extra_charges = 0") +`)) }) +``` + +You should have a fourth `if` statement. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[3]`)) }) +``` + +Your fourth `if` statement condition should be `is_weekend`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[3].find_conditions()[0].is_equivalent("is_weekend") +`)) }) +``` + +You should assign the integer value `2` to `extra_charges` variable inside your new `if` statement. + +```js +({ test: () => (runPython(` +_var = _Node(_code).find_ifs()[3].find_bodies()[0].find_variable("extra_charges") +assert _var.is_equivalent("extra_charges = 2") +`)) }) +``` + +You should print `Extra charges will be applied` inside your new `if` statement. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[3].find_bodies()[0].has_call("print('Extra charges will be applied')") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e2377cacbc46a7f7383a.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e2377cacbc46a7f7383a.md new file mode 100644 index 00000000000..bc60e0b9285 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e2377cacbc46a7f7383a.md @@ -0,0 +1,80 @@ +--- +id: 6958e2377cacbc46a7f7383a +title: Step 13 +challengeType: 20 +dashedName: step-13 +--- + +# --description-- + +Now, add an `else` clause to your `if` statement and print `No extra charges will be applied` inside the `else` body. This will print the message only when the extra charges condition is false. + +Then, below the `else` clause, use the `print()` call to display a message that shows `Extra charges:` followed by the updated value of `extra_charges` and check the output in the terminal. + +# --hints-- + +You should have an `else` clause. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[3].find_conditions()[1].is_empty()`)) }) +``` + +You should print `No extra charges will be applied` inside your `else` clause. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[3].find_bodies()[1].has_call("print('No extra charges will be applied')") +`)) }) +``` + +You should have `print('Extra charges:', extra_charges)` below your `if...else` statement. + +```js +({ test: () => (runPython(` +if_stmt = """if is_weekend: + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied')""" +print_call = "print('Extra charges:', extra_charges)" +assert _Node(_code).is_ordered(if_stmt, print_call) +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend: + extra_charges = 2 + print('Extra charges will be applied') +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e59845777391b86d7331.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e59845777391b86d7331.md new file mode 100644 index 00000000000..8ec8833a430 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958e59845777391b86d7331.md @@ -0,0 +1,115 @@ +--- +id: 6958e59845777391b86d7331 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +In Python, an `if` statement can also be placed inside the body of another `if` statement. This is called a nested `if` statement. + +A nested `if` statement allows you to check an additional condition only after the first condition has already been satisfied. The inner `if` statement will run only if the outer `if` condition is true. + +```py +if condition1: + # Code to execute if condition1 is True + if condition2: + # Code to execute if both conditions are True +``` + +Now you will calculate service charges based on the type of seat the user has selected. + +Still inside your last `if` statement body, create a variable named `service_charges` and set it to `0`. + +Then, create a nested `if` statement to check if `seat_type` is equal to `Premium`. Inside the body of the `if` statement, update the `service_charges` value to `5`. + +# --hints-- + +You should declare a variable named `service_charges` inside your last `if` statement body. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[4].find_bodies()[0].has_variable("service_charges") +`)) }) +``` + +You should assign the integer value `0` to `service_charges`. + +```js +({ test: () => (runPython(` +_var = _Node(_code).find_ifs()[4].find_bodies()[0].find_variable("service_charges") +assert _var.is_equivalent("service_charges = 0") +`)) }) +``` + +You should have an `if` statement inside your last `if` statement body. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[4].find_ifs()[0]`)) }) +``` + +The new `if` statement condition should be `seat_type == 'Premium'`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[4].find_ifs()[0].find_conditions()[0] +assert _cond.is_equivalent("seat_type == 'Premium'") +`)) }) +``` + +You should assign the integer value `5` to `service_charges` variable inside your new `if` statement. + +```js +({ test: () => (runPython(` +_var = _Node(_code).find_ifs()[4].find_ifs()[0].find_bodies()[0].find_variable("service_charges") +assert _var.is_equivalent("service_charges = 5") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member): + print('Ticket booking condition satisfied') + +--fcc-editable-region-- + +--fcc-editable-region-- +else: + print('Ticket booking failed due to restrictions') +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958ea03cb1c4684c138754a.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958ea03cb1c4684c138754a.md new file mode 100644 index 00000000000..78a9d9bac85 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6958ea03cb1c4684c138754a.md @@ -0,0 +1,156 @@ +--- +id: 6958ea03cb1c4684c138754a +title: Step 21 +challengeType: 20 +dashedName: step-21 +--- + +# --description-- + +In this final step, you will calculate the final price of the movie ticket using the values calculated in the previous steps. + +The final ticket price is calculated by adding the extra charges and service charges to the base price, and then subtracting the discount. + +At the bottom of your last `if` statement body, calculate the final price of the ticket and store it in a variable named `final_price`. + +Finally, print a message that shows `Final price of ticket:` followed by the value of `final_price`. + +# --hints-- + +You should declare a variable named `final_price`. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[4].find_bodies()[0].has_variable("final_price")`)) }) +``` + +You should assign the value `base_price + extra_charges + service_charges - discount` to `final_price`. + +```js +({ test: () => (runPython(` +import itertools +perms = itertools.permutations(['+ base_price', '+ extra_charges', '+ service_charges', '- discount']) +values = (' '.join(perm).lstrip('+') for perm in perms) +solutions = (f'final_price = {v}' for v in values) +var = _Node(_code).find_ifs()[4].find_bodies()[0].find_variable("final_price") +assert any(var.is_equivalent(s) for s in solutions) +`)) }) +``` + +You should have `print('Final price of ticket:', final_price)` below your `final_price` variable. + +```js +({ test: () => (runPython(` +print_call = "print('Final price of ticket:', final_price)" +_body = _Node(_code).find_ifs()[4].find_bodies()[0] +assert _body.has_call(print_call) +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member): + print('Ticket booking condition satisfied') + + service_charges = 0 + if seat_type == 'Premium': + service_charges = 5 + elif seat_type == 'Gold': + service_charges = 3 + else: + service_charges = 1 + print('Service charges:', service_charges) + +--fcc-editable-region-- + +--fcc-editable-region-- +else: + print('Ticket booking failed due to restrictions') +``` + +# --solutions-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member): + print('Ticket booking condition satisfied') + + service_charges = 0 + if seat_type == 'Premium': + service_charges = 5 + elif seat_type == 'Gold': + service_charges = 3 + else: + service_charges = 1 + print('Service charges:', service_charges) + + final_price = base_price + extra_charges + service_charges - discount + print('Final price of ticket:', final_price) +else: + print('Ticket booking failed due to restrictions') +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099abb6acc539b27055a1.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099abb6acc539b27055a1.md new file mode 100644 index 00000000000..45956f34d5e --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099abb6acc539b27055a1.md @@ -0,0 +1,55 @@ +--- +id: 696099abb6acc539b27055a1 +title: Step 5 +challengeType: 20 +dashedName: step-5 +--- + +# --description-- + +In the previous step, you checked a condition using an `if` statement. The `else` clause is used to handle the case when the condition is false. Here's the syntax of an `if...else` statement: + +```py +if condition: + # Code to execute if condition is True +else: + # Code to execute if condition is False +``` + +Now, add an `else` clause to your `if` statement and print `User is not eligible for Evening shows` inside the `else` body. This will print only when the condition in the `if` statement is false. + +# --hints-- + +You should have an `else` clause. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[1].find_conditions()[1].is_empty()`)) }) +``` + +You should print `User is not eligible for Evening shows` inside your `else` clause. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[1].find_bodies()[1].has_call("print('User is not eligible for Evening shows')") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099c1ac72a4e585de1d5b.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099c1ac72a4e585de1d5b.md new file mode 100644 index 00000000000..65c5ef7ed40 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696099c1ac72a4e585de1d5b.md @@ -0,0 +1,67 @@ +--- +id: 696099c1ac72a4e585de1d5b +title: Step 6 +challengeType: 20 +dashedName: step-6 +--- + +# --description-- + +Some information can only be true or false. As you have learned in previous lessons, this can be represented using boolean values. + +Create a variable named `is_member` to indicate whether the user is a member and set its value to `True`. + +Below the `is_member` variable create another variable named `is_weekend` to indicate whether the movie show is on a weekend and sets its value to `False`. Do not surround the value with quotes. + +# --hints-- + +You should declare a variable named `is_member`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("is_member")`)) }) +``` + +You should assign the boolean value `True` to `is_member`. Do not surround the value with quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("is_member").is_equivalent("is_member = True") +`)) }) +``` + +You should declare a variable named `is_weekend`. + +```js +({ test: () => (runPython(`assert _Node(_code).has_variable("is_weekend")`)) }) +``` + +You should assign the boolean value `False` to `is_weekend`. Do not surround the value with quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("is_weekend").is_equivalent("is_weekend = False") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a5165f7efe52a0c0aa39.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a5165f7efe52a0c0aa39.md new file mode 100644 index 00000000000..6b5a5ec70a0 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a5165f7efe52a0c0aa39.md @@ -0,0 +1,62 @@ +--- +id: 6960a5165f7efe52a0c0aa39 +title: Step 10 +challengeType: 20 +dashedName: step-10 +--- + +# --description-- + +In Python, the `and` operator is used to check if multiple conditions are true. Here's how you can use it to combine two conditions in an `if` statement: + +```py +if condition1 and condition2: + # Code to execute if all conditions are True +``` + +The membership discount should only apply to members if their `age` is greater than or equal to `21`. + +Use the `and` operator to combine the existing condition of your `if` statement with another condition checking if `age` is greater than or equal to `21`. + +# --hints-- + +Your third `if` statement condition should be `is_member and age >= 21`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[2].find_conditions()[0] +assert _cond.is_equivalent("is_member and age >= 21") or _cond.is_equivalent("is_member and 21 <= age") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = True +is_weekend = False + +discount = 0 +--fcc-editable-region-- +if is_member: +--fcc-editable-region-- + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a848aacf859f7bb15447.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a848aacf859f7bb15447.md new file mode 100644 index 00000000000..b50a3594c37 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960a848aacf859f7bb15447.md @@ -0,0 +1,54 @@ +--- +id: 6960a848aacf859f7bb15447 +title: Step 11 +challengeType: 20 +dashedName: step-11 +--- + +# --description-- + +Now change the value of the `is_member` variable to `False` as the user is not a member. + +After that, you will see that the `discount` value now remains `0`, because both conditions must be satisfied for the discount to apply. + +# --hints-- + +You should update the value of the `is_member` variable to `False`. Do not surround the value with quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_variable("is_member").is_equivalent("is_member = False") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +--fcc-editable-region-- +is_member = True +--fcc-editable-region-- +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b308bf41cc39c9b4b438.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b308bf41cc39c9b4b438.md new file mode 100644 index 00000000000..d7b573dd9bf --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b308bf41cc39c9b4b438.md @@ -0,0 +1,67 @@ +--- +id: 6960b308bf41cc39c9b4b438 +title: Step 14 +challengeType: 20 +dashedName: step-14 +--- + +# --description-- + +In Python, the `or` operator is used to check whether at least one of two conditions is true. Here's how you can use it in an `if` statement: + +```py +if condition1 or condition2: + # Code to execute if any condition is True +``` + +Extra charges should also apply if the show is in the evening. Use the `or` operator to combine the existing condition of your `if` statement with a second condition checking if `show_time` is equal to the string `Evening`. + +# --hints-- + +Your last `if` statement condition should be `is_weekend or show_time == 'Evening'`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[3].find_conditions()[0].is_equivalent("is_weekend or show_time == 'Evening'") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +--fcc-editable-region-- +if is_weekend: +--fcc-editable-region-- + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b6a6ea06e27dcc7eef37.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b6a6ea06e27dcc7eef37.md new file mode 100644 index 00000000000..891ce9adcac --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b6a6ea06e27dcc7eef37.md @@ -0,0 +1,95 @@ +--- +id: 6960b6a6ea06e27dcc7eef37 +title: Step 15 +challengeType: 20 +dashedName: step-15 +--- + +# --description-- + +Now you will check if the user satisfies the conditions to book a movie ticket. Users with age `21` or above can always book tickets without any restrictions. + +Create an `if` statement to check if `age` is greater than or equal to `21`. Inside the body of the `if` statement, print `Ticket booking condition satisfied` to the terminal. + +Then, add an `else` clause to your `if` statement and print `Ticket booking failed due to restrictions` inside the `else` body. + +# --hints-- + +You should have a fifth `if` statement. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[4]`)) }) +``` + +Your fifth `if` statement condition should be `age >= 21`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[4].find_conditions()[0] +assert _cond.is_equivalent("age >= 21") or _cond.is_equivalent("21 <= age") +`)) }) +``` + +You should print `Ticket booking condition satisfied` inside your new `if` statement. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[4].find_bodies()[0].has_call("print('Ticket booking condition satisfied')") +`)) }) +``` + +Your new `if` statement should have an `else` clause. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[4].find_conditions()[1] == _Node()`)) }) +``` + +You should print `Ticket booking failed due to restrictions` inside your `else` clause. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[4].find_bodies()[1].has_call("print('Ticket booking failed due to restrictions')") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b8632b9544d1f57295f4.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b8632b9544d1f57295f4.md new file mode 100644 index 00000000000..a64db03fa5a --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960b8632b9544d1f57295f4.md @@ -0,0 +1,70 @@ +--- +id: 6960b8632b9544d1f57295f4 +title: Step 16 +challengeType: 20 +dashedName: step-16 +--- + +# --description-- + +Users between `18` and `21` can book tickets, but only when the `show_time` is not `Evening`. + +Use the `and` operator to build an expression checking if `age` is greater than or equal to `18` and `show_time` is not `Evening`. Use the `or` operator to combine it with the existing condition of the last `if` statement. Do not create new variables. + +# --hints-- + +Your last `if` statment condition should be `age >= 21 or age >= 18 and show_time != 'Evening'`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[4].find_conditions()[0] +_first = _cond.is_equivalent("age >= 21 or age >= 18 and show_time != 'Evening'") +_second = _cond.is_equivalent("age >= 21 or 18 <= age and show_time != 'Evening'") +assert _first or _second +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +--fcc-editable-region-- +if age >= 21: +--fcc-editable-region-- + print('Ticket booking condition satisfied') +else: + print('Ticket booking failed due to restrictions') +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960ba6e6c95ed4ad896c6f2.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960ba6e6c95ed4ad896c6f2.md new file mode 100644 index 00000000000..4bf8de035b9 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6960ba6e6c95ed4ad896c6f2.md @@ -0,0 +1,77 @@ +--- +id: 6960ba6e6c95ed4ad896c6f2 +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +There is one more exception to the booking rules. Users between `18` and `21` can book evening shows if they are members. + +When multiple logical operators are used in an `if` statement, conditions joined with `and` are evaluated before conditions joined with `or`. Parentheses `()` are used in Python to group conditions and control the order in which they are evaluated. + +```py +if condition1 and (condition2 or condition3): + # Code to execute if conditions evaluate to True +else: + # Code to execute if conditions evaluate to False +``` + +Now, add another condition to your existing `if` statement using the `or` operator to check if `is_member` is truthy. Use the parentheses `()` to group the `show_time != 'Evening'` and `is_member` conditions together as shown in the above example. + +# --hints-- + +Your last `if` statement condition should be `age >= 21 or age >= 18 and (show_time != 'Evening' or is_member)`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[4].find_conditions()[0] +assert _cond.is_equivalent("age >= 21 or age >= 18 and (show_time != 'Evening' or is_member)") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +--fcc-editable-region-- +if age >= 21 or age >= 18 and show_time != 'Evening': +--fcc-editable-region-- + print('Ticket booking condition satisfied') +else: + print('Ticket booking failed due to restrictions') +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cb889fc4fdeb337e52864.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cb889fc4fdeb337e52864.md new file mode 100644 index 00000000000..ed5648618d9 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cb889fc4fdeb337e52864.md @@ -0,0 +1,76 @@ +--- +id: 696cb889fc4fdeb337e52864 +title: Step 8 +challengeType: 20 +dashedName: step-8 +--- + +# --description-- + +In Python, `if` conditions don't have to compare values explicitly to `True` or `False`. Instead, they rely on the truthiness of values. Truthy values evaluate to `True` in a boolean context, such as the condition of an `if` statement. These include non-zero numbers, non-empty strings, and the boolean value `True`. + +```py +if value: + print('value is truthy') +``` + +Create an `if` statement to check if `is_member` is truthy. Inside the body of the `if` statement, update the `discount` value to `3` and print `User qualifies for membership discount` to the terminal. + +# --hints-- + +You should have three `if` statements in your code. + +```js +({ test: () => (runPython(`assert _Node(_code).find_ifs()[2]`)) }) +``` + +Your third `if` statement condition should be `is_member`. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[2].find_conditions()[0].is_equivalent("is_member") +`)) }) +``` + +You should assign the integer value `3` to `discount` variable inside your new `if` statement. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[2].find_bodies()[0].find_variable("discount").is_equivalent("discount = 3") +`)) }) +``` + +You should print `User qualifies for membership discount` inside your new `if` statement. Remember to surround the message with single or double quotes. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[2].find_bodies()[0].has_call("print('User qualifies for membership discount')") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = True +is_weekend = False + +discount = 0 +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cbb3985e23420cd45c58f.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cbb3985e23420cd45c58f.md new file mode 100644 index 00000000000..87dd04694a0 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/696cbb3985e23420cd45c58f.md @@ -0,0 +1,119 @@ +--- +id: 696cbb3985e23420cd45c58f +title: Step 20 +challengeType: 20 +dashedName: step-20 +--- + +# --description-- + +The `if...elif...else` statement is used to check multiple conditions in order. + +```py +if condition1: + # Code to execute if condition1 is True +elif condition2: + # Code to execute if condition2 is True +else: + # Code to execute if all conditions are False +``` + +Add an `elif` statement to your `if...else` statement and check if `seat_type` is equal to `Gold`. Inside the body of the `elif` statement, update the value of `service_charges` to `3`. + +Below the `if...elif..else` statement, use the `print()` call to display a message that shows `Service charges:` followed by the updated value of `service_charges`. Then, check the output in the terminal. + +# --hints-- + +You should have an `elif` statement. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[4].find_ifs()[0].find_conditions()[1] +assert not _cond.is_empty() +`)) }) +``` + +Your `elif` statement condition should be `seat_type == 'Gold'`. + +```js +({ test: () => (runPython(` +_cond = _Node(_code).find_ifs()[4].find_ifs()[0].find_conditions()[1] +assert _cond.is_equivalent("seat_type == 'Gold'") +`)) }) +``` + +You should assign the integer value `3` to `service_charges` variable inside your `elif` body. + +```js +({ test: () => (runPython(` +_var = _Node(_code).find_ifs()[4].find_ifs()[0].find_bodies()[1].find_variable("service_charges") +assert _var.is_equivalent("service_charges = 3") +`)) }) +``` + +You should have `print('Service charges:', service_charges)` below your `if...elif...else` statement. + +```js +({ test: () => (runPython(` +if_stmt = """if seat_type == 'Premium': + service_charges = 5 +elif seat_type == 'Gold': + service_charges = 3 +else: + service_charges = 1""" +print_call = "print('Service charges:', service_charges)" +assert _Node(_code).find_ifs()[4].find_bodies()[0].is_ordered(if_stmt, print_call) +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member): + print('Ticket booking condition satisfied') + + service_charges = 0 + if seat_type == 'Premium': + service_charges = 5 +--fcc-editable-region-- + + else: + service_charges = 1 +--fcc-editable-region-- +else: + print('Ticket booking failed due to restrictions') +``` diff --git a/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6970f09b547e10402abf2847.md b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6970f09b547e10402abf2847.md new file mode 100644 index 00000000000..9b7df864045 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-movie-ticket-booking-calculator/6970f09b547e10402abf2847.md @@ -0,0 +1,79 @@ +--- +id: 6970f09b547e10402abf2847 +title: Step 19 +challengeType: 20 +dashedName: step-19 +--- + +# --description-- + +Now, add an `else` clause to your `if` statement and update the `service_charges` value to `1` inside the `else` body. + +# --hints-- + +Your new `if` statement should have an `else` clause. + +```js +({ test: () => (runPython(` +assert _Node(_code).find_ifs()[4].find_ifs()[0].find_conditions()[1].is_empty() +`)) }) +``` + +You should assign the integer value `1` to `service_charges` variable inside your `else` clause. + +```js +({ test: () => (runPython(` +_var = _Node(_code).find_ifs()[4].find_ifs()[0].find_bodies()[1].find_variable("service_charges") +assert _var.is_equivalent("service_charges = 1") +`)) }) +``` + +# --seed-- + +## --seed-contents-- + +```py +base_price = 15 +age = 21 +seat_type = 'Gold' +show_time = 'Evening' + +if age > 17: + print('User is eligible to book a ticket') + +if age >= 21: + print('User is eligible for Evening shows') +else: + print('User is not eligible for Evening shows') + +is_member = False +is_weekend = False + +discount = 0 +if is_member and age >= 21: + discount = 3 + print('User qualifies for membership discount') +else: + print('User does not qualify for membership discount') +print('Discount:', discount) + +extra_charges = 0 +if is_weekend or show_time == 'Evening': + extra_charges = 2 + print('Extra charges will be applied') +else: + print('No extra charges will be applied') +print('Extra charges:', extra_charges) + +if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member): + print('Ticket booking condition satisfied') + + service_charges = 0 + if seat_type == 'Premium': + service_charges = 5 +--fcc-editable-region-- + +--fcc-editable-region-- +else: + print('Ticket booking failed due to restrictions') +``` diff --git a/curriculum/structure/blocks/workshop-movie-ticket-booking-calculator.json b/curriculum/structure/blocks/workshop-movie-ticket-booking-calculator.json new file mode 100644 index 00000000000..5c242d69943 --- /dev/null +++ b/curriculum/structure/blocks/workshop-movie-ticket-booking-calculator.json @@ -0,0 +1,33 @@ +{ + "name": "Build a Movie Ticket Booking Calculator", + "isUpcomingChange": false, + "dashedName": "workshop-movie-ticket-booking-calculator", + "helpCategory": "Python", + "blockLayout": "challenge-grid", + "challengeOrder": [ + { "id": "694a9ff65d4472dd451d8255", "title": "Step 1" }, + { "id": "694cc1b515976889afd4cded", "title": "Step 2" }, + { "id": "6958dd85587e10c99162dd81", "title": "Step 3" }, + { "id": "6958de0d773289a89515a6b8", "title": "Step 4" }, + { "id": "696099abb6acc539b27055a1", "title": "Step 5" }, + { "id": "696099c1ac72a4e585de1d5b", "title": "Step 6" }, + { "id": "6958dfa0c74b237e1b56ce04", "title": "Step 7" }, + { "id": "696cb889fc4fdeb337e52864", "title": "Step 8" }, + { "id": "6958e0ecc121b0ae3dd9c5e0", "title": "Step 9" }, + { "id": "6960a5165f7efe52a0c0aa39", "title": "Step 10" }, + { "id": "6960a848aacf859f7bb15447", "title": "Step 11" }, + { "id": "6958e1875e592b58e8852757", "title": "Step 12" }, + { "id": "6958e2377cacbc46a7f7383a", "title": "Step 13" }, + { "id": "6960b308bf41cc39c9b4b438", "title": "Step 14" }, + { "id": "6960b6a6ea06e27dcc7eef37", "title": "Step 15" }, + { "id": "6960b8632b9544d1f57295f4", "title": "Step 16" }, + { "id": "6960ba6e6c95ed4ad896c6f2", "title": "Step 17" }, + { "id": "6958e59845777391b86d7331", "title": "Step 18" }, + { "id": "6970f09b547e10402abf2847", "title": "Step 19" }, + { "id": "696cbb3985e23420cd45c58f", "title": "Step 20" }, + { "id": "6958ea03cb1c4684c138754a", "title": "Step 21" } + ], + "blockLabel": "workshop", + "usesMultifileEditor": true, + "hasEditableBoundaries": true +} diff --git a/curriculum/structure/superblocks/python-v9.json b/curriculum/structure/superblocks/python-v9.json index 58b175b457d..4dc707a61b9 100644 --- a/curriculum/structure/superblocks/python-v9.json +++ b/curriculum/structure/superblocks/python-v9.json @@ -12,6 +12,7 @@ "lecture-introduction-to-python-strings", "lecture-numbers-and-mathematical-operations", "lecture-booleans-and-conditionals", + "workshop-movie-ticket-booking-calculator", "lecture-understanding-functions-and-scope", "workshop-caesar-cipher", "lab-rpg-character",