CET111 Fall 2023 Midterm Exam - Model B PDF

Document Details

CheaperRhythm7214

Uploaded by CheaperRhythm7214

2023

Tags

Python programming questions computer programming midterm exam programming

Summary

This document contains a set of multiple-choice questions from a computer programming midterm exam. The questions cover topics such as Python programming concepts, code execution, and various basic programming tasks. The exam is Fall 2023 and the format is Model B.

Full Transcript

# CET111 - Introduction to Computer and Programming - Midterm Exam ## Fall 2023 - Model B - **Instructors:** Prof. M. Sobh, Dr. A. Taha - **Time allowed:** 60 mins - **Maximum Grade:** 15 ## Exam Instructions: * This is MCQ Exam, consists of 60 Questions in 6 pages. * The act of keeping the mob...

# CET111 - Introduction to Computer and Programming - Midterm Exam ## Fall 2023 - Model B - **Instructors:** Prof. M. Sobh, Dr. A. Taha - **Time allowed:** 60 mins - **Maximum Grade:** 15 ## Exam Instructions: * This is MCQ Exam, consists of 60 Questions in 6 pages. * The act of keeping the mobile phone active while inside the examination room is considered cheating and subject to disciplinary action. If it is necessary to bring the mobile phone, It must be turned off and placed in your bag. * The use of earphones or Bluetooth devices is not allowed as well as bringing any books, notes, or papers into the examination room and any violation will be considered cheating. ## Questions: ### 1. For a list with length equals 8 the statement x[-3] is equivalent to: * a. x[4] * b. x[5] * c. x[6] * d. x[7] ### 2. How does the "elif" statement differ from the "else" statement in Python? * a. "elif" is used for error handling, while "else" is used for conditions. * b. "else" is used when there are multiple conditions, and only one should be executed. * c. "elif" is used when there are multiple conditions, and only one should be executed. * d. There is no difference; they can be used interchangeably. ### 3. Considering the following code, what is the output? ```python x = 5; y = 10 if x > 3: y = y + 5 else: y = y print(y) ``` * a. 5 * b. 10 * c. 15 * d. 20 ### 4. Considering the following code, what is the output? ```python count = 0 while count <= 2: print("Hello") count+=1 ``` * a. Hello * b. Hello\nHello * c. Hello\nHello\nHello * d. It prints nothing ### 5. Considering the following code, what is the output? ```python num = 11 if num % 2 == 0: num = num / 2 print(num) ``` * a. 11 * b. 5.5 * c. 5 * d. 0 ### 6. Considering the following code, what is the output? ```python x = 7 if x < 10 and x > 8: x = x * 2 elif x < 10 or x > 8: x = x / 2 elif x < 10 and x > 5: x = x - 2 else: x = x + 3 print(x) ``` * a. 14 * b. 3.5 * c. 5 * d. 10 ### 7. Given the student variable below, which line of code prints the third degree: ```python student = {'name': 'ahmed', 'degrees': [44, 55, 12]} ``` * a. print(student['degrees'] [3]) * b. print(student['degrees':3]) * c. print(student.degrees [2]) * d. print(student['degrees'][2]) ### 8. What does the len() function return when applied to a list? * a. The sum of elements in the list * b. The number of elements in the list * c. The average of elements in the list * d. The maximum value in the list ### 9. What is the output of following program: ```python if 5!=5 or 7>7: print("A") elif not (5!=5) and 7>7: print("B") elif 5!=5 or -7>-8: print("C") else: print("D") ``` * a. A * b. B * c. C * d. D ### 10. Following command create a folder "books" * a. makefolder books * b. mkfolder books * c. createdir books * d. mkdir books ### 11. The output of following program is: ```python x = 5; x += x + x; print(x) ``` * a. 5 * b. 10 * c. 15 * d. 20 ### 12. The output of following program is: ```python x = 19%7; print(x) ``` * a. 5 * b. 4 * c. 2.713 * d. 2 ### 13. The output of following program is: ```python print("%0.3e"%(2/3)) ``` * a. 0.667 * b. 0.667e-00 * c. 6.667e-01 * d. 0.6666666667 ### 14. The following program prints the time table of 7, there is a syntax error, which line? ```python y = 7; x = 1 while x > 10: print(str(x) "*" str(y) " = " str(x*y)) x = x + 1 ``` * a. Line 1 * b. Line 2 * c. Line 3 * d. Line 4 ### 15. The output of following program is: ```python print("({2}+{0})/({0}*{1})".format(2,3,5)) ``` * a. (5+2)/(2*3) * b. (3+2)/(5*3) * c. (5+3)/(3*2) * d. (2+5)/(5*3) ### 16. What is the data type of the variable x in the statement x = 'Hello'? * a. Integer * b. String * c. Float * d. Boolean ### 17. Select a code that can be used to evaluate the expression: $ \frac {(x+7)}{ (\frac{y}{(x+8)})^2} ^3$ * a. result = math.pow((x+7)/math.pow(y/(x+8),2),math.pow(3,-1)) * b. result = math.pow(x+7/math.pow(y/x+8,2),1/3) * c. result = math.pow((x+7)/math.pow(y/(x+8),2),3) * d. result = math.pow((x+7)/math.pow(y/(x+8),0.5),1/3 ### 18. Following is an example of IP addresses: * a. 9.8:7.5:3.4:1.2 * b. S34:TN2:1SL:4R2 * c. www.google.com * d. 192.128.133.1 ### 19. Gateway are used to: * a. Control communication inside LAN * b. Type of server can be used to operate important software in any organization * c. Connect LAN to Internet * d. Protect LAN from cyber attacks ### 20. Which of the following ways are used to save image files: * a. ASCII * b. UTF8 * c. PNG * d. JPN ### 21. How do you remove the last element from a list? * a. list.remove(-1) * b. del list[-1] * c. del list[len(list)] * d. list.clear(-1) ### 22. The output of following program is: ```python s = "7 + 8 + 15"; print(s) ``` * a. 7+8+15 * b. 30 * c. s = 30 * d. Error message ### 23. The output of following program is: ```python print(math.floor(-2.8)) ``` * a. -2 * b. -2.8 * c. -3 * d. 2.8 ### 24. The output of following program is: ```python print(int(9.9)) ``` * a. 9 * b. 9.9 * c. 10 * d. Error ### 25. Considering the following code, what is the output? ```python num = 8 while num > 0: print(num) num = num - 2 ``` * a. 8642 * b. 87654321 * c. 852 * d. 2468 ### 26. Bits are stored in CD and DVD as: * a. 1 for magnetized 0 for non-magnetized * b. 1 for pit 0 for land * c. 1 for hole 0 for no-hole * d. 1 for open 0 for close ### 27. … is an example of volatile memory: * a. ROM * b. Register * c. Flash Memory * d. Punched Cards ### 28. 1GB is exactly equivalent to: * a. 1024 KB * b. 1000 MB * c. 1024*1024 KB * d. 1024 TB ### 29. [copy image.png ..] means * a. Copy the file "image.png" to root folder * b. Copy the file "image.png" to parent folder * c. Copy the file "image.png" to child folder * d. Incorrect command ### 30. [cd ..] means * a. Go to a children directory of name [..] * b. Go to the parent directory * c. Go directory to the children directory * d. Go to the root directory ### 31. What is the correct way to empty a list in Python? * a. list = [] * b. list = () * c. list = () * d. del list ### 32. To change the name of a file using windows command line: * a. cn data.txt newdata.txt * b. changename data.txt newdata.txt * c. rename data.txt newdata.txt * d. cn data.txt to newdata.txt ### 33. Following program will not work because: ```python x = 8483784; print(y) ``` * a. Undefined variable * b. Value out of range * c. Missing brackets * d. Each call must be in separate line ### 34. The output of following program is: ```python x = "5" + '6'; print(x) ``` * a. 11 * b. 56 * c. 0 * d. Error message ### 35. How do you access the third element in a list named my_list? * a. my_list(2) * b. my_list[3] * c. my_list[2] * d. my_list.third ### 36. If the user types Ahmed, the output of the following program will be: ```python name = input("Enter name:"); print("Hello", x) ``` * a. Hello Ahmed * b. HelloAhmed * c. Hello, Ahmed * d. Gives Error ### 37. Which of the following variables is incorrect: * a. vALUe * b. first name * c. x1182 * d. a_b_c_d ### 38. The output of following program is: ```python x = 100; x += 200; x = "Ahmed"; print(x) ``` * a. 100200Ahmed * b. 300Ahmed * c. Ahmed * d. Error message ### 39. Which of the following programs loops forever. ```python #Program 1 x = 0 while True: x += 1 if x>5: break print("done") #Program 2 x = 5 while True: x += 1 if x<5: break print("done") #Program 3 x = 5 while True: x += 1 if x>5: break print("done") #Program 4 x = 5 while True: x = 1 if x<5: break print("done") ``` * a. Program 1 * b. Program 2 * c. Program 3 * d. Program 4 ### 40. In Python, how is the code block under an "if" statement indicated? * a. Using parentheses * b. Using square brackets * c. Using curly braces * d. Using indentation ### 41. What is the output of following program: ```python x = 15; y = 12; z = -17; print(x > 15 and y > 13, not (y < x) or z >-20) ``` * a. False False * b. False True * c. True False * d. True True ### 42. Select a code that can be used to evaluate the expression: $ (\frac { (x+7)}{ (\frac{y}{(x+8)})^2} )^3$ * a. result = math.pow((x+7)/math.pow(y/(x+8),2),math.pow(3,-1)) ### 43. How is a tuple defined in Python? * a. Using square brackets [] * b. Using curly braces {} * c. Using parentheses () * d. Using angle brackets <> ### 44. The following program prints list items, there is a program error, in which line? ```python x = [1, 2, 3, 4, 5] print(x[5]) print(x[-5]) print(x[1:3]) print(x[len(x)-1]) ``` * a. Line 1 * b. Line 2 * c. Line 3 * d. Line 4 ### 45. What is the output of following program: ```python x = 1; s = 0 while x < 10: s += x; x += 2 print(s) ``` * a. 0 * b. 20 * c. 25 * d. 45 ### 46. What is the result of len(('apple', 'banana', 'cherry'))? * a. 3 * b. 6 * c. 12 * d. 1 ### 47. Considering the following code, what is the output? ```python value = 5 while value > 1: print(value); value = 1 ``` * a. 5, 4, 3, 2, 1, 0 * b. 5, 4, 3, 2, 1 * c. 5, 4, 3, 2 * d. 4, 3, 2 ### 48. What is the primary characteristic of a set in Python? * a. Ordered collection of elements * b. Immutable collection of elements * c. Unordered collection of unique elements * d. Mutable collection of key-value pairs ### 49. Consider the following code, what will be the output? ```python for i in [8,13,22,28,33,60]: if ((1+1)%2)==0: print(i) ``` * a. 13 22 28 33 60 * b. 8 22 28 60 * c. 13 33 * d. 8 60 ### 50. Cache memory can have following size: * a. 4 bytes * b. 4 MB * c. 4 GB * d. 4 TB ### 51. What does the term "hardware" refer to in the context of computers? * a. Computer programs * b. Physical components * c. Data files * d. Output devices ### 52. What is the output of following program: ```python x = 5; f = 1 while x > 0: f *= x; x -= 1 print(f) ``` * a. 1 * b. 45 * c. 120 * d. Nothing ### 53. What is the purpose of a "while" loop in Python? * a. To iterate over a sequence of values * b. To perform a specific action a fixed number of times * c. To execute a block of code repeatedly as long as a certain condition is true * d. To define a function ### 54. The following prints the length of x (a multi value variable), what is the output? ```python x = {1, 2, 2, 6, 2, 4, 1, 4} print(len(x)) ``` * a. 7 * b. 6 * c. 8 * d. 10 ### 55. What is the output of the following program? ```python x = [12, 22, 15, 13, 11, 14, 7, 3] print(x[4:7]) ``` * a. [14, 7, 3] * b. [11, 14, 7, 3] * c. [11, 14, 7] * d. [13, 11, 14, 7] ### 56. What is the output of the following program? ```python x = [12, 22, 15, 13, 11, 14, 7, 3] print(x[-6]) ``` * a. 22 * b. 15 * c. 13 * d. 11 ### 57. Which method is used to add an element at the end of a list? * a. add() * b. insert() * c. append() * d. extend() ### 58. Which types of computers are designed for complex mathematical and scientific computations? * a. Microcomputer * b. Mainframe computer * c. Supercomputer * d. Minicomputer ### 59. What is the purpose of a device driver in an operating system? * a. Manage system resources * b. Control input devices * c. Communicate with hardware components * d. Provide security features. ### 60. For a tuple x of length equals 4 following statement is not allowed: * a. print(x[3]) * b. z = x[2] * c. x += [4] * d. print(x[-3:-1]) ## Answer Key 1) b 2) c 3) c 4) c 5) a 6) b 7) d 8) b 9) c 10) d 11) c 12) a 13) c 14) c 15) a 16) b 17) a 18) d 19) c 20) c 21) b 22) a 23) c 24) a 25) a 26) b 27) b 28) b 29) d 30) d 31) a 32) c 33) a 34) b 35) c 36) d 37) b 38) c 39) b 40) d 41) b 42) c 43) c 44) b 45) c 46) a 47) c 48) c 49) c 50) b 51) b 52) c 53) c 54) a 55) c 56) b 57) c 58) c 59) c 60) c

Use Quizgecko on...
Browser
Browser