0% found this document useful (0 votes)
60 views10 pages

Midterm 60f

Computer Science

Uploaded by

S a r a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
60 views10 pages

Midterm 60f

Computer Science

Uploaded by

S a r a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
What is the print out of the following program? Student ID, a:[i=3 2: | if 1 > 5: 3: | print("a") a:| if i = Si] print(*b") else: print("c") va b 2) a ab 4) 5) None of the above What is the print out of the following program? x=2 xox*24*3424242/2 3: | print(x) 1) 257.0 2) 2049.0 3) 2050.0 4) 264450.0 5) 524289. Let ¢ and £ be variables, which choice is used to find the value of F from these python expressions? © / 5 = (F-32) 19 1) (F-32)/9 = e/5 2) f= (32 + 0)/5/9 3) f = 32 + (c/5*9) 4) £-32 = c/5#9 5) ¢/5#9-32 = What is the print out of the following program? a: [a = "Hello" b= ‘World* c= 2017 string1 = a+b print(string1) string2 = arbec print (string2) 41) The program prints out only ‘HelloWor 1d" and finishes without any error. 2). The program prints out "Hel loWior1d" and “Hel loWor1d2017" 3). The program cannot print anything because ¢ is not a string 4) The program cannot print anything because + can be used with number only. 5) The program prints ‘HelloWorld” and stop with error message. From the following program a: [x = int(input()) y = int(input()) if approve(x,y: print("This is good if we want the print out to be "This is good.” when y equals x raised to the power of 3, which choice is the correct "approve(x,y)" function? °) [def approve(): return x*x*x 2) [def approve(a,b) if atata return True else: return False 3) [def approve(a,b): if x3 = ys return False else: return True 4) [det approve(x,y): return if xxx 5) [deF approve(x,y): return x*x*x ‘What is wrong with the following “code” for opening a bottle. 1: Grip cap with index finger and thumb. Remove cap. ‘Twist counter-clockwise until seal is broken. 41) The code has too many steps 2) The instructions are not specific 3) The code does not apply to other bottles. 4) The instructions are out of sequence. 5) All of the above choices (01204111 Computer and Programming, Midterm Examination, 1° Semester/2017 EXAM SET 1 Student 10, 7. The computer itself uses __ language. 11. What isthe output of the following program? 41) natural a: [a= ‘Apple’ 2 ‘Banana’ 2) python pvt 3: |¢ = "Cherry" 3) machine 4: | def hello fruit(a, b, ¢): 4) highlevel 5: | print(F*Hello, {a+b} and {c}.") 5) Allof the above choices | edter Leute (U-EeEe)) 1) Hello, Apple Banana and Cherry 2) Hello, Banana Apple and Cherry 3) Hello, Banana Apple and Banana 4) Hello, Bananatpple and Banana 8) The program has an error. 8, The following variables and their data type are correct EXCEPT which one? 41) number = 1234 has the class int 2) true = 2.543 has the class float 3) is-ok = False has the class bool 4) hello = ‘HelloWorld" has the class string 5) STRING = "Hey!" has the class string 12, What is the output of the following program? = 30 9.32 2 if ake asad if ac b 9. What is the output of the following program? a: [def hello_world(name): 28: print(fHello, (name).*) bec hello_world('Boyza") elif type(a) == float: a = int(a) 1) Boyza 2) Hello, (name). 3) Hello, Boyza. print(f'a = {a}, b = {b}, ¢ = {c}") 4) Hello, "Boyza’. 1) a= 20, b= 9.32, ¢=2 eee 2) a= 30, b= 9.32, c= 10 3) a= 30, b= 9.32, c=2 10. What is the output of the following program if 4) a = 20.68, b = 9.32, c=2 suppose that the user enters 3.2 as an input? 5) a= 20.68, b=2,c=2 a: | deF compute_circle(r): area = 3.14*r*#2 return area r= int(input(‘Enter a radius: ')) 13. What is the output of the following code fragment? area = conpute_circle(r) aaeletate) print(farea of a circle with {r} is tre {area:.2F}') a) 1) Enter a radius: 3.2 elif a > b: Area of a circle with 3.2 is 32.15 ee) 2) enter a radsus: 3.2 aaa Area of a circle with 3 1s 32.15 eran 3) Enter a radius: 3.2 print("A") Area of a circle with 3 is 28.26 def c(): 4) Enter a radius: 3.2 print("a") Area of a circle with r is area:.2f def ae ) program has an error DEanE Ges B) Ta eT as b¢*HEI", "Hin" 1) B 2a 3c 4) AB 5) BC (01204111 Computer and Programming, Midterm Examination, 1" Semester/2017 EXAM SET 1 For blanks (A) and (B), both places requite the correct syntaxes to make the program runs correctly 4a: 5: 6: Student 10, Tv = 3000 def cal_tv(quantity): as ty = int(input ("How many TVs? print(f'Total is {__(B)__] » ) 4) 5) 6000 6200 1000 6000 None 7020 17. At line 6, which staterent should replace print (SALARY) so that the program prints the output as shown below? Example output: How many TVs?: 3 Total is 9000 14, What should be put at the blank (A)? 1) 2) 3) 4) 5) print (quantity*tv) print(tv#Tv) return total = TVtv return quantity*IV return (quantity*tv) 415. What should be put at the blank (B)? 1) 2) 3) 4) 5) cal_tv(quantity) cal_tv(1v) cal_tv(tv) cal_tv(tv):.2F cal_tv(tv*quantity) Use the following code fragment to answer the next 2questions. 10: SALARY = 6000 def b(): = 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 1 Name. 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 1 25, 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 SETH 29, 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 1 37. 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 1 43, 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 1 49, 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 1 sr. 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

You might also like