top of page

Topic 6: Problem solving with programming

PART 5- 6.5 OPERATORS

On this page is:

  • Activities

  • What You Need To Know

 

Workbook 1- Data Types

a) Complete the code in this workbook based on the theory you have learnt

b) Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler

#WORKBOOK 1 Data Types
print ("Welcome to my data types workbook")
print ("division example below")
print ("Here is my division of 5 divided 3",5/3)
print ("multiplication example below")
#>>
print ("exponentiation example below")
#>>
print ("addition example below")
#>>
print ("integer division (integer part of result) example below")
#>>
print ("subtraction example below")
#>>
print ("modulus (remainder after division) example below")
#>>

#------Q2) Code examples of Relational/Logical operators : --------------------->>>>>>>---------------------------------->>>>>>
print ("Not equal to example below")
#>>
print ("Greater than example below")
#>>
print ("Greater than or equal t example below")
#>>
print ("Less than example below")
#>>
print ("Less than or equal to  example below")
#>>

#------Q3) Code examples of Boolean operators : --------------------->>>>>>>---------------------------------->>>>>>

print ("and- Returns true if both conditions are true example below")
#>>
print ("or- Returns true if one of the conditions is true example below")
#>>
print ("not- Reverses the outcome of the expression; true becomes false, false becomes true... example below")
#>>

 

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

Workbook 2- Baby? Child? Teenager? Adult?

Sasha wants a system to automatically work out where you are in your growth as a human based on your age. Sasha has done Pseudocode with some errors.....can you make it into Python code using operators.

 .

a) Complete the code in this workbook based on the theory you have learnt

b) Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler

print (" Welcome to my age checker"
age=int(input("Whats your age?"))
if age is equal to 0
    print ("Are you a baby?")
elif age is less than or equal to 12
    print (You are a child)
elif age is greater than 13 and less than 20:
    print ("You are a teenager")
else age is greater than 19:
    print ("You are an adult")

 

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

Workbook 3- Operator Operator

a) Complete the code in this workbook based on the theory you have learnt

b) Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler

print ("If I add 4 and 20 i get the sum:",add code here)
print ("If I minus 4 from 20 i get the sum:",add code here)
print ("If I divide 20 by 4 i get the sum:",add code here)
print ("If I multiple 4 by 20 i get the sum:",add code here)
print ("4 by the power of 4 is:",add code here)
print ("The remainder of 20 divided by 8 is:",add code here)
print ("The number of times that 3 goes into 10 is:",add code here)

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

Workbook 4- Ellie's Code

Ellie's code is trying to make sense. She wants to ask them for two numbers and then by the choices they enter..... do the relevant calculation. But it doesnt work. Please fix and finish it

a) Complete the code in this workbook based on the theory you have learnt

b) Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler

print ("Welcome to my Operators program")
num1=int(imput("Give me a first number")
num2=int(imput("Give me a second number)
print("Ok choose what you want to do with the numbers")
print ("Press 1 to add them")
print ("Press 2 to subtract 1st number and 2nd number")
print ("Press 3 to multiply 1st number and 2nd number")
print ("Press 4 to divide 1st number and 2nd number")
choices=input("What is your choice?")
if choice=="1":
    print("The answer is",num1 plus num1)
elif choice=="2"
    print("The answer is",???)
elif choice==3
    print(The answer is",???)
elif choce=="4"
    print("The answer is",???)

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

Workbook 5- Odd Or Even Number

Tommy wants a system to work out if a number if odd or even. He has had a go but is stuck

CLUE 1 which mathematical operator would help here? 

CLUE 2 if the answer is 0 the number is even

a) Complete the code in this workbook based on the theory you have learnt

b) Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler

answer=int(input("Is my number I am entering an even or odd number?
remain=answer??
if remain==??:
    print ("The answer is an even number")
else:
    print ("The answer is odd number")

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

In the following area you will:

6.5.1 be able to write programs that use arithmetic operators (addition, subtraction, division, multiplication, modulus, integer division, exponentiation)
6.5.2 be able to write programs that use relational operators (equal to, less than, greater than, not equal to, less than or equal to, greater than or equal to) 

6.5.3 be able to write programs that use logical operators (AND, OR, NOT)

Arthimetic Operators

 

+    Addition                  x + y    
-    Subtraction              x - y    
*    Multiplication         x * y    
/    Division                    x / y    
%    Modulus                 x % y    
**    Exponentiation    x ** y    
//    Floor division         x // y

Comparison Operators


==    Equal                                     x == y    
!=     Not equal                              x != y    
>      Greater than                         x > y    
<      Less than                               x < y    
>=    Greater than or equal to    x >= y    
<=    Less than or equal to          x <= y    

Logical Operators

and     Returns True if both statements are true                       x < 5 and  x < 10    
or        Returns True if one of the statements is true                x < 5 or x < 4    
not      Reverse the result, returns False if the result is true    not(x < 5 and x < 10)    

bottom of page