|||
Accessibility Settings

Y10 AU – CT4 – Conditionals and Relational Operators

Copy this title into a new OneNote document:

Y10 AU – CT4 – Conditionals and Relational Operators

(1) Copy the code below into raspberry pi code editor

(2) Follow the instructions directly below each arrow comment block

(3) Add a subheading Do It Now into the OneNote

(4) Paste a screenshot of your complete code below the subheading

# DIN - Y10 AU - CT4

#-------------------- Global Variables ------------------

beatle = ""     # Initialising a variable called beatle

#-------------------- Main Program -----------------------

# Assigning an input to the beatle variable
beatle = input("Input the name of one of the Beatles: ")


#====> Complete a branched conditional sequence
#====> It will respond with correct if the user's response is
#====> paul, john, ringo or george



🎯 Objectives:

(1) We will be able to identify key features of a program that includes conditional sequences

(2) We will be able to describe the role of each relational operator

(3) We will be able to develop branched conditional sequences, involving both string and integer data

✍️ Code Annotation

(1) Screenshot the code below into OneNote

(2) Annotate it with the following:
————————————————————–

  • Initialisation of a variable
  • Assignment of a value to a variable
  • A prompt
  • Relational operator
  • Conditional sequence
  • Identify the type of data in each variable
  • Identify an example of casting
  • Overall, explain how the program works
# Activity 1 - Code Labelling Task

#-------------------- Global Variables ------------------

name = ""

age = 0

#-------------------- Main Program -----------------------

name = input("Input your name: ")


age = int(input("Enter your age: "))


if age >= 11:
    print(f"Nice to meet you {name}")
    print(f"You can attend TGGS")

    
else:
    print(f"Nice to meet you {name}")
    print(f"Unfortunately you can't attend TGGS")

📖 Relational Operators

When testing a condition we place a relational operator between both values:

OperatorMeaningExample (each would be True)
==Equal toif “a” == “a”:
!=Not equal toif “a” != “b”
>Greater thanif 5 > 2:
<Less thanif 2 < 5:
>=Greater than or equal toif 10 >= 9: or if 10 >= 10:
<=Less than or equal toif 9 <= 10: or if 9 <= 9:

⌨️ Activity

(1) Create a folder called Y10 AU – CT4 – CS and RO

(2) Create a file in the folder called Activity 2 – Relational Operators.py

(3) Copy the code below into it

(4) Follow the instructions in each arrow comment block to complete the program

(5) Copy the complete code into today’s OneNote

# Y10 AU - CT4 - Activity 2 - Relational Operators

#------------------- Global Variables -----------------------

num1 = 0      # Initialising num1 as an integer

num2 = 0      # Initialising num2 as an integer


#--------------------- Main Program -------------------------

#====> Replace each instance of (    ) with what is needed
#====> Assign a suitable value to each variable
#====> Use the equal to operator to make this work

num1 = (    )
num2 = (    )

if num1 (    ) num2:
    print("Number 1 is equal to Number 2")




#====> Replace each instance of (    ) with what is needed
#====> Assign a suitable value to each variable
#====> Use the not equal to operator to make this work

num1 = (    )
num2 = (    )

if num1 (    ) num2:
    print("Number 1 is not equal to Number 2")




#====> Replace each instance of (    ) with what is needed
#====> Assign a suitable value to each variable
#====> Use the greater than operator to make this work

num1 = (    )
num2 = (    )

if num1 (    ) num2:
    print("Number 1 is greater than Number 2")




#====> Replace each instance of (    ) with what is needed
#====> Assign a suitable value to each variable
#====> Use the less than or equal to operator to make this work

num1 = (    )
num2 = (    )

if num1 (    ) num2:
    print("Number 1 is less than or equal to Number 2")

⌨️ Coding Challenges

(1) Make a new file for each of the coding challenges below

(2) Complete the instructions in the arrow comment blocks

(3) Evidence your code in OneNote

⌨️ Activity 3a.py

# Activity 3a

#------------- Global Variables ------------------

age = 0

#------------- Main Program ----------------------

#====> Assign an input to the age variable
#====> Make sure you cast it to integer
#====> The prompt will ask the user to enter their age


#====> Create an age verification program for a video streaming service
#====> 18 and above is "18 Cert"
#====> 15 and above is "15 Cert"
#====> 12 and above is "12 Cert"
#====> 10 and above is "12a Cert"
#====> 7 and above is "PG Cert"
#====> Any other age is "U Cert"



⌨️ Activity 3b.py

# Activity 3b

#------------- Global Variables ------------------

temperature = 0

#------------- Main Program ----------------------

#====> Assign an input to the temperature variable
#====> Make sure you cast it to integer
#====> The prompt will ask the user to enter the current temperature



#====> Create a weather advice program
#====> 30 and above is "Heatwave Warning"
#====> 20 and above is "Warm"
#====> 10 and above is "Mild"
#====> 0 and above is "Cold"
#====> Any other temperature is "Freezing"

⌨️ Activity 3c.py

# Activity 3c

#------------- Global Variables ------------------

age = ""

#------------- Main Program ----------------------

#====> Assign an input to the age variable
#====> The prompt will ask the user to enter their age
#====> You will need to cast age to an integer, only when relevant


#====> Create a program that tells them if they are old enough to go to TGGS
#====> If they input "eleven" the output will be "You are old enough to attend TGGS"
#====> If they input "11" the output will be "You are old enough to attend TGGS"
#====> If they input 11 the output will be "You are old enough to attend TGGS"
#====> If they input a number greater than 11 the output will be "You are old enough to attend TGGS"
#====> Any other input will be "You are not old enough to attend TGGS".



🙋🏽‍♀️ Mini Whiteboard Activity

Access the mini-whiteboard app and join with the code your teacher has provided.

You will then answer from the following questions:
——————————————————————-

(1) What is the relational operator for greater than or equal to?

(2) What is the relational operator for not equal to?

(3) What is the relational operator for equal to?

(4) Why do we cast inputs to a different value?

(5) What three words are used in a branched conditional sequence?