...

Back to Leadership Board

Challenge #2: Decision Maker

Start Date: October 20, 2023
Submit By: 8:30 am on October 27, 2023

In this project, you will learn how to use conditional statements and create a decision-making questionnaire/survey using if/else and elif statements.
We will cover the following:

  •     Conditional statements
  •       How to use If/Else and Elif statements
  •       Create a Decision Making Questionnaire/Survey
Watch a Video Tutorial

Video Tutorial

Challenge #2: Decision Making Questionnaire

Design a Python program that conducts a decision making questionnaire or survey on any topic of your choice and provides different outcomes based on the answers given by the participant.

Challenge Details:
  • Create Your Questionnaire: Create a new Trinket and name it "challenge2"
  • Begin with Yes/No: Start your questionnaire with a simple Yes/No question.
  • Dive Deeper: In the next level of questions, go beyond Yes/No. Each possible answer should provide at least three different choices, much like the restaurant survey example.
  • Guide the Way: Use if, else, and elif statements to guide your program in different directions.
  • Collect the Answers: Use the input function to collect answers to your questions
Bonus Tip: The more creative and engaging your questionnaire is, the more points you can earn in this challenge.
Too Hard? If this is too challenging to create your own multi-level survey, just follow any of the if/elif/else samples, and you can still receive 3 points.
Next
Learn about if/elif/else

IF / ELSE Conditions

In programming, if/else conditions are used to make decisions based on certain conditions. They allow the computer to execute different blocks of code depending on whether a condition is True or False.

In coding, indentation is the practice of using spaces or tabs at the start of lines of code to visually arrange and indicate which lines are grouped together. This helps the computer understand which instructions go together and which are separate, ensuring it follows the correct sequence.

The Basic Structure

The if keyword is followed by the condition you want to check. If the condition is True, the code indented under if will be executed. If the condition is False, the code under else will be executed.


Using elif for Multiple Conditions

If you have multiple conditions to check, use elif (short for "else if"). It allows you to evaluate different conditions one by one. The code under the first true condition will be executed.

How to construct an if/elif/else statement in Python:

  1. Start with the "if" keyword.
  2. After "if," write the condition you want to check.
  3. Add a colon ":" after the condition.
  4. Indent the code that belongs to this "if" statement by using spaces or tabs (typically four spaces).
  5. If you need to check additional conditions, use "elif" (short for "else if").
    1. Start with "elif."
    2. Write the condition after "elif."
    3. Add a colon ":" after the condition.
    4. Indent the code for the "elif" block.
  6. If none of the previous conditions are met, use "else."
    1. Simply write "else:" with no condition.
    2. Indent the code for the "else" block.

Conditional Operators and Comparisons

Python uses several conditional operators for comparisons. Here are some common ones:

  • : Checks if two values are equal.
  • : Checks if one value is greater than another.
  • : Checks if one value is less than another.
  • : Checks if one value is greater than or equal to another.
  • : Checks if one value is less than or equal to another.

Example 1: Checking if a Student Passed or Failed

Example 2: Weather-Based Outfit Decision

Example 3: Restaurant Survey

Prev Next
Submit your Challenge

Submit your final project




Copy your Trinket Url

  • Click Share->Link
  • Copy the link to share your code
  • Paste link into the field


  • Prev