
Climate Quest - Task 6
Objectives
- Understand selection in algorithms and code.
- Define the purpose of selection (conditional statements) in programming.
- Learn the syntax of
if,elif, andelsestatements in Python. - List and explain the relational operators used in conditions (e.g.,
==,!=,>,<,>=,<=). - Review examples of conditional statements.
- Define the role of the
elifstatement in handling multiple conditions. - Differentiate the use of
eliffromifandelse.
Task Overview:
In this homework, you will enhance the "Climate Quest" project by incorporating selection statements (if, elif, and else) to make decisions within the game. These decisions will impact the gameplay based on the player's choices and environmental conditions.
There are two main occasions when a selection is required:
- User is presented with the menu of locations and is asked to select one to visit
- In that location, user is presented with up to 3 actions and to choose one of those actions
Instructions:
-
Process the location selection from the menu
- Get the location choice from the user
- Select the correct location challenge function based on that choice
-
Add Selection Statements in Challenges:
- In each location challenge the user is presented with 3 options to choose from
- Add functionality to process this choice
-
Role of
elif:- Demonstrate the role of
elifin handling multiple conditions.
- Demonstrate the role of
Detailed Steps:
-
Add Selection statements for the main menu
Having displayed the main manu of locations, get the user choice and branch to the selected location:
-
Add selection statements for each of the challenges
Each challenge contains three options. Add these options and get the choice made by the user.
-
Selection Statements for the final comment
- To practice working with relational operators, when the game is complete there will be a final score representing the impact the choices have had on climate change.
- Assuming the score starts at 0, this will be added to as the game progresses.
- Positive impacts will increase the score, negative impacts will decrease the score.
- When the game is complete the final score should be presented to the user and a comment selected based on that final score.
- For example, if the score is greater than, say, 10 the comment might be "Great job! There has been a major improvement in the state of the climate".
- Write a function
display_final_score(score)that displays a different comment based on the final score ```
-
Define Relational Operators:
Explain the relational operators used in the conditions within the function. For example: -
>: Greater than ->=: Greater than or equal to -<: Less than -<=: Less than or equal to -==: Equal to -!=: Not equal to -
Role of
elif:The
elifstatement allows you to check multiple conditions. It stands for "else if" and is used when you need to handle more than two conditions. -
Add the score variable
As each challenge is completed, and each choice made in a location a
scorevariable will need to be updated. Add this variable to the challenge functions.
Homework Questions:
-
Add Selection Statements:
- Enhance the
ocean_challenge()andforest_challenge()functions to useif,elif, andelsestatements for different scenarios based on user input.
- Enhance the
-
Define Relational Operators:
- Identify and explain the relational operators used in your conditions for the final comment.
-
Role of
elif:- Describe the role of the
elifstatement in handling multiple conditions. How is it different fromifandelse?
- Describe the role of the
-
Keeping score
- Maintain a score representing the environmental health of the planet that is updated each time the user visits a location and takes a decision