Preview

04 - Arithmetic operators MOD, DIV EXP etc

 1. Read the following excerpt and definition of operators and fill in the blanks.
Operators are special _________in Python that carry out arithmetic or 
logical computation. The value that the operator operates on is called 
the ________

  symbols / operand

  addition signs / operation

  symbols / operation

  signs / opulents

 2. The '+' operator performs

  division

  multiplication

  subtraction

  addition

 3. The '*' operator performs both subtraction and multiplication

  TRUE

  FALSE

 4. Analyse the code below which uses the '/' divide operator. What is the output?
x=5
y=2
z=x/y
print(z) #this is also called Division (float)

  3.5

  2

  3

  2.5

 5. The Division(floor) operator which is a // acts differently from a single /. What is the output here?
  x=5
  y=2
  z=x//y
  print(z)

  2

  3

  2.5

  

 6. __________returns the remainder when first operand is divided by the second

  REM ( R )

  DIV(//)

  /

  MOD (%)

 7. if a = 10 and b = 20, then a**b =

  10 x 20 x 10

  20 to the power of 10

  10 to the power 20

  10 x (20x10)

 8. 9//2 =

  4.5

  4

  2.5

  3.5

 9. 8 MOD 4 (or 8%4) =

  0

  1

  3

  2

 10. Consider this expression and discuss the answer - what is the result in python? >> - 5 MOD 3 =

  0

  3

  2

  1

 11. We use modulo arithmetic every day. Read the following excerpt and fill in the blanks.
When reckoning hours, we count up to 12 and start again from one. 
Thus, four hours after 9 o’clock it is 1 o’clock. Numbers that 
differ by a multiple of the __________are said to be congruent 
modulo 12.

  modulus 11

  modulus 13

  modulus 12

  modulus 14

 12. Suppose today is Thursday. What weekday will it be 1,000 days from today?

  1000%7 = 6 and the weekday 1000 days from today will be the same as in six days -i.e Wednesday

  This cannot be worked out without very complex maths and a super computer

  1000 // 7 = 142 and 142 / 100 is the MODULUS remainder of 2, which gives us Monday

  Tuesday - and this can only be worked out by looking up a digital calendar

 13. Decide whether the following excerpt on the practical applications of MOD is true or false
It is used to calculate checksums for international standard book numbers 
(ISBNs) and bank identifiers (Iban numbers) and to spot errors in them.
Modular arithmetic also underlies public key cryptography systems, which 
are vital for modern commerce

  FALSE

  TRUE

 14. What does the function 'convert' do, and what two operators does it use?
def convert(num):
    if num > 1:
        convert(num // 2)
    print(num % 2)


# decimal number
num= int(input("Enter any decimal number: "))

convert(num)

  It takes text and converts it into numeric output using DIV and MOD

  It takes a whole number (integer) and converts it into a real number using MOD and float DIV

  It takes a binary number and converts into a decimal number using MOD and the '+' operator

  It converts a decimal number into a binary number using floor DIV and MOD

 15. What is the order of precedence in python?
E - Exponential
M - Multiplication
S -  Subtraction
D - Division
A - Addition
P -  Parentheses (or B for Brackets)

  DMASPE

  MASPED

  PEDMAS

  EDMASP