0% found this document useful (0 votes)
4 views2 pages

Python - Conditional Statement Tasks

The document provides three examples of programs that use conditional statements to interact with users. Example 1 determines the color resulting from mixing red and blue, Example 2 evaluates test scores for star awards, and Example 3 checks a user's guess against a stored number. Each example outlines the conditions and corresponding outputs based on user input.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python - Conditional Statement Tasks

The document provides three examples of programs that use conditional statements to interact with users. Example 1 determines the color resulting from mixing red and blue, Example 2 evaluates test scores for star awards, and Example 3 checks a user's guess against a stored number. Each example outlines the conditions and corresponding outputs based on user input.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

Example 1

A program asks the user to enter the colour that is made when red and blue are mixed. It puts one
message if the input "purple", a diferent messgae if they input "green", another different message if
they input "orange", another different messgae for "yellow" and another different message if they
imput anything else.

1. The first condition is: If the input equals purple


2. If condition 1 is try, output is correct
3. If condition 1 is fals, condition 2 is: If the input equals green
4. f condition 2 is true, output "Green is made from yellow and blue"
5. If condition 1 and 2 are false, condition 3 is: If input equals orange
6. If condition 3 is true, output "Orange is made from red and yellow"
7. If condition 1, 2 and 3 are false, condition 4 is: If the input equals yellow
8. If condition 4 is true, output "Yellow is a primary colour"
9. If conditions 1, 2, 3 and 4 are false, output "Sorry, the answer is purple"

Example 2
A program asks the user to enter the percentage they scored on a test and outputs whether they got a
gold star (80% or mroe), a silver star (60% or more), a bronze star (50% or more) or if they did not
pass (less than 50%).

1. Condition 1 is: If the percentage is 80 or more.


2. If it is true, output "Gold star".
3. If condition 1 is false, condition 2 is: If the percentage is 60 or more.
4. If it is true, output "Silver star".
5. If conditions 1 and 2 are false, condition 3 is: If the percentage is 50 or more.
6. If t is true, output "Bronze star."
7. If conditions 1, 2 and 3 are false, output "You needed 50% to pass".)

Example 3
A program asks the user to guess the number the program has stored (50) and outputs a message
telling them if they got it correct, or if they guessed too high or too low.

1. The first condition is: If the user enters the number 50


2. If it is true, output "That's correct!"
3. If condition 1 is false, condition 2 is: If the number is mroe than 50.
4. If it is true, output "Too high"
5. If conditions 1 and 2 are false, condition 3 is: If the numer is less than 50.
6. If it is true, output "Too low"
Example 1

colour = input("What colour is made when red and blue are mixed?")
if colour == "purple":
print("That is correct")
elif colour == "green":
print("Green is made from yellow and blue")
elif colour == "orange":
print("Orange is made from red and yellow")
elif colour == "yellow":
print("Yellow is a primary colour")
else:
print("Sorry, the answer is purple")

Example 2

score = int(input("Enter your percentage"))


if score >= 80:
print("Gold star")
elif score >= 60:
print("Silver star")
elif score >= 50:
print("Bronze star")
else:
print("You needed 50% to pass")

Example 3

number = 50
answer = int(input("Guess what numer I have stored"))
if answer == numer:
print("That's correct")
elif answer > number:
print("Too high")
elif answer < number:
print("Too low")

You might also like