Here are some example questions for our upcoming midterm exam. Think like a Python interpreter and do your best :)

Question 1

1

Answer:

2 30 5
14 28 0

 


Question 2

 

2

Answer:

q2(__3_ , __2__) Answer1 q2(__5_ , __5__) Answer5
q2(__8_ , __4__) Answer2 q2(__2_ , __3__) Answer6
q2(_11_ , __1__) Answer3 q2(__3_ , __4__) Answer7
q2(_10_ , _11__) Answer4 q2(__0_ , __0__) Answer8

Question 3

 

3

Answer:

5 0
10 2
15 4

 


Question 4

 

4

Answer:

XXX:A.?B.?C.?5
XXX:A.?B.?C.?6
XXX:A.?B.?C.?7
XXX:A.!B.!C.!8
XXX:A.!B.!C.!9
YYY

 


Question 5

 

5

Answer:

Answer 1: 3
Answer 2: 4 10

 


Question 6

 

6

Answer:

animal1 = input("Give me an animal name: ")
while len(animal1) < 5:
print("Animal name must include at least 5 characters!")
animal1 = input("Give me an animal name: ")
animal2 = input("Give me an another animal name: ")
while len(animal2) <= len(animal1):
print("Second animal name must include more characters than first animal name!")
animal2 = input("Give me an animal name: ")

Question 7

 

7

Answer:

34
37
40
44
44
k = 13

Question 8

 

8

Answer:

q8

 


Question 9

 

9

Answer:

def query_point(x1, y1, x2, y2, x3, y3):
if x1 == x3 or x2 == x3:
print("on edge")
elif y1 == y3 or y2 == y3:
print("on edge")
elif x1 < x3 < x2 and y1 < y3 < y2:
print("inside")
elif x2 < x3 < x1 and y2 < y3 < y1:
print("inside")
elif x1 < x3 < x2 and y2 < y3 < y1:
print("inside")
elif x2 < x3 < x1 and y1 < y3 < y2:
print("inside")
else:
print("outside")

Question 10

 

10

Answer:

def middle(a, b, c):
if a > b > c or c > b > a:
print(b)
if b > c > a or a > c >b:
print(c)
if c > a > b or b > a > c:
print(a)
if a == b or b == c or a == c:
print("error")

Question 11

 

11

Answer:

This function finds the number of numbers that has bigger value than aritmetic mean of a list of numbers
Bu fonksiyon sayı dizisindeki aritmetik ortalamadan büyük sayıların sayısını bulur

Question 12

 

12

Answer:

def fact(n):
r = 1
while (n>=2):
r = r * n
n = n - 1
return r

Question 13

 

13

Answer:

Expression Value Expression Value
5*3-2**2 6 20%(5+2)*3 18
24/6*2 8 (48/(10-2))-(57//8)+2 1
10*(1+(1+3)**(12%5)-2) 150 (7-4)*3-(8-9) 10

Question 14

 

14 14-2

Answer:

a = 20
b = 9
while a > b:
if b % 2 == 0:
a -= 1
b += 3
elif b % 3 == 0:
b -= 1
else:
b += 1
a -= 1
print(str(a) + " " + str(b))
print("DONE")