Midterm 60f
Midterm 60f
= 38 or y > 10: a() if x <= 28 and y < 1@:= 15: aQ elif x >= a() else: aQ) def a(): print("a") def c(): print("B") def d(): print("c") (30,25) 18, What is the output? » 2) 3) 4) 5) rN ¢ parroane (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 1Name. 19. 20. 2t 22, What is the output if line 18 has been changed to b(19,24)? 1) 2) 3) 4) 5) por panprer What are reasons we write programs in high-level Languages such as Python instead of machine instructions? (A) Programs are easier to read by programmers. (8). Programs can run much faster. (©) Programs are easier to understand by machines. (0) Programs are easier to spot errors, (€) Programs require less time to develop. 1) (B)and(C) 2) (A), (0), and (€) 3) (A), (©), and (0) 4) (®), (0), and (&) 5) (8), (©), and (E) Let x be a variable of type int, which Boolean expression is always false? 1) x<=10 and x>=20 2) x<=10 and x<=20 3) x¢a10 on x>=20 4) x!=10 and x!=20 Student 10, 5) 1@¢=x and x<=20 Given the following two functions: a: [def #00: 2:| return 2*x+3 3: | deF g(x): 4:| return 10% Let y be a variable of type Float. What is the value of F(a(y))? 4) 20543 2) 20ye3 3) 20y+30 4) 20y'+30 5) 10y°+3 23, From the flowchart, which choice gives the best explanation about x and y when the black $ is executed? 4) yisnote 2) yequals® 3) xis less than S@ and y is not @ 4) xis greater than or equal to 58 and y equals @ 5) y isnot equal tox 24, Which code fragment is corresponding to the flowchart? °) [iF x0: if x<50: if yt sQ 2) (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 125, 26. Student 10, 3) [GF ete: 1) [det midpoint (a, yl, x2, v2): ») xem (axa) /2 case SF 0: ye Quyay/2 «0 teturn xexye ea 2) [GeF midpoint Gay, 2,92): case: xe'= (x02) /2 50) yc = (x24y2)/2 9) [def midpoint (x: x : oleae a lameetec meee Pees return (y14y2)/2 a 4) [def midpoint (cd, y1,x2, y2): elif return (x1-x2)/2, (y1-y2)/2 RQ) el else: def midpoint (xi, y2,x2,y2): sQ return (x1+x2)/2,(y1+y2)/2 5) [iF xe1@ and x<5@ and y! ss.) else: PC) a) 27 Fill nthe blank (2) to complete the following RO) program, numa = float(input("1st number:")) sch Python expression cowespon rund = float (input ("2nd nunber:")) Which Python expression corresponds to the aga of ume = Fyoae empat tr the grey region, given that the math module is “Guess the average:")) already imported? avg = (numi+num2)/2.8 iF guess < ave: print("It 1s too low") (aaa f print("TE is too high") else: Na print(*It is correct!") 1) eLiF guess > avg: 4) (math. pi*R*R)-(2*R#R) 2) else guess > avg 2). (R*#2)-(nath.pi*R*R) 3) else: guess > avg: 3) (4*R*R)=(math.pL*R*R) 4) elif: guess > av 4), (Math. PL*R*R) -(24R*R) 5) elif guess >= avg: 5) (Math. PI*R*2) -(2*R*R) 28, Fil in the blank (2) to complete the following Which definition of the function midpoint () correctly computes and retums the middle point, program such that it can prevent a dvide-by-zero ertor. (xca¥e), that is located between two points numa = float (input(“ast nunber:")) es hum2 = float input("2nd munber:)) if ___(1)__. (392) print(numi, ‘is divisible by‘ ,num2) +) ((numa % numa) == @) 2) (num % nun2) == @ and num2 > 0) 2 3) ((numi % nun2) == @ or nun2 != 0) Ca¥) 4) (num % num2) == @ and num > ) 5) (numa t= @ and (num % nun2) == 0) 1204111 Computer and Progamming Materm Damnation, 1 Semester 2017 DAM SETH29, The expression 2°*344//2 is equal to which of the following expressions? 1) 2**(344//2) 2) 2¥4(344)//2 3) (2e344)//2 4) 29934(4//2) 5) None of the above answers at Student 10, Given the following variable assignments: a, b= 5,4 xy = 5.0, 4.0 Which of the following expressions have the value of 1? 1) (a/b) 2) (ab) 3) Gly) 4) int(x/y) 8) Choices 2) and 4) only Given the following variable assignments: Which of the following expressions have the value of True? 1) (ror (y = x) 2) (y == 9) and ((x >= 2) or r) 3) (x+y) > (46 - 2) 4) x == (21) +2 5) All of the above answers What is the result of the following program? def f(x): x= 10 x=5 F(x) print(x) 1) 10 25 3) @ 4) 15 5) None of the above answers 33, What does the following code do? a 2 » 2) 3) 4) 5) def a(b, c, 4) pass defines a function and initializes it. defines a function, which does nothing, defines a function, which returns its parameters. defines an empty class None of the above choices is correct. 34. What gets printed? x= 45 y=2 print(x//y) 2.8 2.25 9.0 20.25 21 36, What gets printed? x = True y = False z = False if not x or y: print (1) elif not x or not y and z: print(2) elif not x or y or not y and x: print(3) else: print (4) 1 2 3 4 ERROR, this code will not run. 36. Which choice yields a different value than the rest? » 2 3) 4) 5) math.sqrt(16) math. floor(4.3) math. pow(16,0.5) math.ceil(3.5) math. 1og(4) (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 137. Student 10, 40. Consider the following statements: A: | print(f"area is {area}" if (point < 68): print ("Poor") elif (point < 78): print("Fair") elif (point < 89): print ("Good") else: print ("Excellent") Which value range of point always yields the output to be Fain? 41) point is greater than or equal to 78 but is less than 89. 2) point is less than 86. 3) point is greater than or equal to 68 but is less than 78 4) point is less than 7. 5) Allof the above choices are correct. Which value range of point always yields the output to be Excellent? 1) point is greater than 88. 2). point is greater than or equal to 8@. 8) point is less than 8@ but is greater than 5@. 4) point is less than 78. 5) All of the above choices are correct. All of the following expressions can be used to calculate shade area correctly, except which one? (3 1) math.pi*R*R-math.pitrtr 2)_math.pitmath.pow(R,2)-math.pow(n,2) 3) math. pir(-R*-R-r#-r) 4) math. pit(R-n)*(r4R) 5) math.pit(-r**2+n**2) 41 42, 8: [r = int (input(msg)) c: [area = 3.14*r*r p: [msg = “Input radius: ” which choice is the correct order to calculate circle area? 1) ABCD 2) BCD. 3) B0,GA 4) BGA 5) 0,688 Consider the code fragment, which choice gives different result when replacing (1)? def Mi(a,b): return xy def M2(a,x): return xy def M3(b,y): return x+y def ma(x,y): return xy x=10 y = 20 —@__ 1) print(maGuy)) 2) print(M2(x,y)) 3) print(M3(qy)) 4) print(Ma(x,y)) 5) All of the above choices give the same result. ‘What is the output of this code fragment? a: [der MOGy): return x+2,y-1 auawn print(f"{a} {6}") yon 2) 10 10 3 119 4) 128 5) 137 (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 143, 44, 45, What is the output of this code fragment? Student 10, def M(a): return x+a x=2 a= M(1) a = Ma) x = Ma) a= M(x) print (a-x) n7 2) 5 33 4a 5) @ What choice gives the maximum value? a: [deF SOuy): return y,x def M(x,y)! a:| if Gey): 5: xy = S(KY) 6:| return x-y 1) M(20,3@) 2) (20,15) 3) M(8,3) 4) M(1,15) 5) M(@,-10) Which of the following method find the minimum of three numbers conectly? a: | def min(a,b,c): if a>b and boc: return c elif boc and cra: return 2 elif coa and arb: return b B: | def min(a,b,c): mea if mb: m=b if mc mec return m def min(a,b,c): if acb: 46. 47. 48, ya 28 ac 4) Bande 5) Aand Band C Which code fragment returns the same output when x is equal to 10” A: [if x >= 10: If x >= 20: print(1) else: print(2) else: print(3) 8: [if x >= 10: print(1) elif x >= 20: print (2) else: print(3) if x < 10: print(3) elif x < 20: print (2) else: print (1) 1) AandB 2) Rand 3) Bande 4) and Bandc 5) All fragments are different. ‘Which command causes an error? 1) Ant ('2"#'8"#!17") 2) int(3.1416) 3) Ant (Float ("3.5") 4) int("3.5") 5) int(7.5//3) Which is a valid statement? 1) x "4" + int("s") 2) = int ("5") 3) * ant ("5") 4) 7 int ("5") 5) None of the above is correct. (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 149, What type of data that we SHOULD use to store the 51 number of students in a class? 1) bool 2) float 3) int 4) string 5) Choices 2) and 3) are both suitable Consider the following command: Student 10, a = float(input(‘Enter A: ')) What will happen if user enters the following value 32 41) Ttwill respond with an error. 2) awill be equal to 6. 3) awill be equal to 3, 4) it will prompt the user to reenter another value. 5) None of the above choices is comect. ‘Suppose user uses python to run the following ‘commands: >>> a= >>> b= 2 What will happen if user enters the following for the next shell command? >>> i f(a>b) 41) Ttwill respond with an error. 2) twill proceed to the command prompt, ready for the next command 3) Itwill allow user to finish the if statement. 4) It will respond with "False’ 5) None of the above choices is conect. What is correct about the following python script? a=10 b=5 false = a>b if (False): print(a) else: print(b) 41) It contains an error as it uses a reserved word, 2) 10 will be displayed on the screen. 3) Swill be displayed on the screen. 4) It contains an error as the expression a > b cannot be assigned to the variable false. 5) If-else statement is incorrectly written. 53, Why MUST we use string, instead of int or float, to store a phone number? 1) We're not going to do any calculation anyway. 2) It makes the program simpler. 3) Ituses the least memory resource. 4) Phone number may begin with @, which may have issue ifit’s stored as int or float. 5) None of the above choices is correct. grade="F* 5 = int(input(‘Input score: ')) elif s>=60: grade="C' else: grade='D" print(grade) 54, Which one in the correct answer? 41) The program cannot run, as there isa syntax error. 2) Some integer inputs, for example a negative value, can cause the program to produce a runtime error. 3) The program will print B when the input is 69. 4) The program will print D when the input is 39. 5). The program will print F when the input is @ 55, Which one in the correct answer? 1) Whenever the user provides 69 as the input to the program, it will print B and stop running 2) Whenever the user provides 69 as the input to the program, it will print B and wait for the next input. 3). The program will always print F for whatever provided input which is less than 42. 4) The input less than @ will cause the program to print 0 5) None of the above answers is correct. (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 1sr. Student 10, a or head oF —_O print(“bee") ——@)__ elif if 8>11@ and A: print( butterfly") if Boiss: ae peat ‘Apple") print(‘cockroach") print(*Mango" c: elif B>=135 and not A: print(‘ant') iF 8155: elif con oF n print(‘Cherry") print(‘bee’) else: elif econ oF n¢e7: print (‘Orange’) print(' butterfly") aise: else: print( ‘Durian") print(‘cockroach') b: [if acen and ne=2: Which choice to fill in the blanks (1) and (2) will print(‘ant") cause the progam to pint Cherry on the screen? elif 30m and nc 1) CQ): A= True calf Geen and ne B= 116 print(‘butterfly’) 2) (): A= False ese: B= 146 print(‘cockroach') 3) (2): A= False ; B= 152 ee 4) : A= True cts 1B = 163 3) BD 5) A= False 4) BC 1B = 156 Which choice to fill in the blanks (1) and (2) will ‘cause the program to print ‘Orange’ on the screen? 1) (2): A = True (2): B= 110 2) A= False :B= 146 3) (41): A = True : B= 152 4) (1): A= True B= 163 5) (1): A = False 8 = 156 Let n be equal to 3, which pair of the following i else blocks give the same print out for whatever value of n? a and print(‘ant*) elif n==3 and n: print('bee') elif n==6 and n: print( butterfly’) else: print(‘cockroach*) 5) None of the above answers is correct. Use the following program to answer the next 2 questions. a: | n= int(input()) 2: | if 1% 3: | if n=77: a: if ne=777: 5 print(‘Earth') 6: else: 7 print(‘Mars') 8: | else: 9: | _print(‘Venus") '59, Which input value of n will let the program print "Earth on the screen? 1) ass 2) 218 3) 6a 4) 784 5) None of the above answers is correct. 60. Which input value of n will let the program print ‘Venus’ on the screen? 1) 162 2) 280 a7 4) 784 5) None of the above answers is cortect. (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 1