menu

Use a conditional statement to run different code based on a given value.

Using Python, write a conditional statement which runs different code blocks based on a predetermined value in the program.

To claim this badge, you may either provide evidence from an existing project OR complete the student task. Both assessment options are detailed below.

As well as providing code evidence, you must also answer a series of questions about your conditional code.

Project-Based Assessment

For this assessment, you can use one or more conditional statements in your existing project code as evidence of understanding.

You will need to show the code to your mentor and then answer the questions described under “Assessment Questions” below.

Task-Based Assessment

This task is designed to assess whether you understand how to run different pieces of code based on a given value.

You may use web search to complete this task, including the Python documentation and StackOverflow. All research and compilation of the code must be your own work.

You will need to show the code to your mentor and then answer the questions described under “Assessment Questions” below.

  1. Create a new script called call-me-maybe-task.py.

  2. Prompt the user to enter how many coffees they had today.

  3. Respond accordingly:
    0 coffees: “Wow, good on ya!”
    1 coffee: “Just getting started eh…”
    2 coffees: “Hmm. About average!”
    3 or more: a randomly chosen response from:
    “Whoa! Are you still feeling okay?”
    “Slow down there buddy!”
    “Are you sure that was a good idea?”

  4. Make sure the program doesn’t crash if an invalid value is entered.

Assessment Questions

Using either your own project code OR the code from task described above, answer each of the following questions about the conditional:

  1. What are the possible values of a Boolean?
    List all possible values.

  2. What are the three key words you can use to build a conditional statement?
    These are the words you use to begin a conditional block.

  3. Which of these key words are optional, and under what conditions?
    Explain when each is used and their dependency on one another.

  4. Does the order of conditional code blocks matter? Why?
    You may reference your code to explain this answer.

  5. What happens if the conditional statement for more than one block evaluates to True?
    When more than one conditional block’s tests could be true, which code will run?

  6. How might you re-implement this conditional so that it uses fewer code blocks?
    Describe how you might implement this conditional using a different structure (if possible), and the pros and cons of each approach.

View Assessor Guide

Assessor Checklist

  1. Uses a well-structured conditional statement.
  2. Uses well-scoped variables.
  3. Produces the correct result.
  4. Includes clear and descriptive comments.
  5. Program handles invalid input.
  6. Provided satisfactory answers to assessment questions.