Week 6


Question 1 d)

Question 2 d)

Question 3 Answer is 81

def double(x): 

calc = x * x 

return calc


 x = 3 

y = double((double(x))) 

# calc= 3*3 = 9 

#9*9=81

print(x, y)



Question 4 a) Both a and b have valid syntax but the brackets are old Python

Question 5 a) 

Question 6 d)

def smallest(x, y):

 if  y>x: 

 return x

 else: 

return y


Question 7 d) Because target changes in the function

target = 0 

for i in range(2,6):  

target = target + i*i  

print ( i ) 

print (target )


Question 8 a) 

Question 9 b)

Question 11 d) invalid syntax

Question 11 b)

Question 12 b)

def test(x):

 print (x*2) 

#104

test(10 * 5 + 1 * 2) 

#52


Question 13 d)

def truetest(x,z,y): 

return  y + z - x 

#30+20-10 = 40

print (truetest(10,20,30))


Question 14 a)

def ex1(x): 

return ex2(x + 2) 

#12+2

def ex2(y): 

#14

return y / 2 

#7

print(ex1(12))


Question 15 b) The loop is going to exit before going to 21

a = 5 

while a < 20: 

print (a) 

#5,7,9,11,13,15,17,19

a +=2

Question 16) c) It makes them easier to understand but comments won't adhere to the speed of the actual programme

Question 17) d) any data

Question 18) Prints 2 

Question 19) b) To break a loop and go on with the code


Question 20) b) First we do the division and then the multiplying

a = 2 

b = 3 

print(a/b*b*10) 

Leave a comment

Log in with itch.io to leave a comment.