Skip to main content

Chapter 4b - Conditionals

๐Ÿ‘€

If Conditionโ€‹

isHot = int(input("Is it hot outside? Enter 1 if it is"))

#use if statement to check if user has entered 1
if isHot == 1:
print('Outside is hot') # Line 9

๐Ÿงช Try the code out~!

Else Conditionโ€‹

isHot = int(input("Is it hot outside? Enter 1 if it is"))

#use if statement to check if user has entered 1
if isHot == 1:
print('Outside is hot') # Line 9
else:
print("not hot")

๐Ÿงช Try the code out~!
Exercise 1

Fix the following program Problem:

  • No matter what you enter it prints "Outside is hot"
  • Fix the program so that it prints "Outside is hot" if isHot = 2
Time to work on our project!

Click here to go to Zodiac Sign Project

You only need to complete this for this class. But if you would like to, feel free to peek into the topics below!

Checking Even and Odd numbers:โ€‹

๐Ÿ‘€ Lesson 4 Learning Activities [R] : Practice Activity 3 - Mathworks

  • If number is odd the following program will print false.
  • If number is even, the program will print true


number = 4

print( number % 2 == 0)

Exercise 2
  • Modify the following program so that if the number is odd, it prints: is Odd
  • And if it is even, it should print: is Even

๐Ÿ™†โ€โ™€๏ธ Expected Program:

Dictionary Orderโ€‹

๐Ÿ‘€ Lesson 4 Learning Activities [R] : Practice Activity 5 - Dictionary Order

Exercise 3

Write a program that asks user to enter 2 words and outputs them in the order they appear in the dictionary.

  • hint: try running "Bruce" < "Atom"

๐Ÿ™†โ€โ™€๏ธ Expected Program:

Guessing Gameโ€‹

๐Ÿ‘€ Lesson 4 Learning Activities [R] : Practice Activity 6 - Secret Word

Exercise 4

In this game, you define a secret word and have the user of the game guess the secret word. Give the user two hints to help guess the word. The hint could be description of the word or partial secret word. Display the appropriate description of the game, first hint and prompt for the user to guess the word. If the user guesses the word then display success message and exit the game. If not then display the second hint. If the user is unable to guess the secret word after all the hints then display the secret word at the end of the game.


๐Ÿ™†โ€โ™€๏ธ Expected Program:


๐Ÿ‘จโ€๐Ÿ”ฌ Feel free to use this template

Quiz About Meโ€‹

๐Ÿ‘€ Lesson 4 Learning Activities [E2] : Python Challenge 4b - Quiz About Me

Exercise 5

Create the following quiz but for yourself


๐Ÿ™†โ€โ™€๏ธ Sample Program:


๐Ÿ‘จโ€๐Ÿ”ฌ Feel free to use this template