Midterm 2021 2022 Sol
Midterm 2021 2022 Sol
Page2
CMPE-CMSE 107
Foundations of Computer-Software Engineering Page3
Page4
Spring-2021-22 (28-04-2022) Midterm Exam
Page5
Total five pages (including the cover page), four parts, 95 minutes.
- Answers that are not written into the given boxes WILL NOT BE GRADED.
- Student who ATTEMPT TO CHEATING will GET ZERO for the exam, and may
be directed to disciplinary investigation for further punishment. Sharing
pen, pencil, eraser, and sharpeners is considered as attempt to cheating.
- Remove all notes, books and unnecessary objects from your desk.
Keep only THIS BOOKLET, PEN-PENCIL-ERASES AND YOUR ID CARD on
your desk.
- Talking, making any kind of noise, asking questions are not allowed. Do
not talk, and do not create any sound once the exam is started.
QB5) The _______ function is used to display QB16) _______ statements are used for the
information on the screen in Python? construction of definite loops only.
Answer ???:
print Answer ???:
for
QB6) Given that 22/7= 3.142857142857143,
print(format(0.1*22/7, '.3e')) displays ??? QB17) The built-in ________ function in Python can
Answer ???:
3.143e-01 be used for generating a sequence of integers.
Answer ???:
QB7) _______ is a finite number of clearly range
described, unambiguous, “doable” steps that can be
systematically followed to produce a desired result
QB18) Examine the following lines of Python code:
for given input in a finite amount of time.
Answer ???:
Algorithm
PART C: FILL IN BLANKS QUESTIONS QC5) (4pts) The following program is prepared to
Write answers only into the answering box. remove repeated elements from a list ListA and
obtain a new list ListB of unique elements.
QC1) (2pts) The following python code is prepared to Complete the empty lines for this purpose.
compute the Area of the shaded space (AoSh). Fill
the missing statements 1 and 2 accordingly to
compute AoSh.
Area of circle (AoC) = 3.142 × 𝑟 2,
Area of rectangle (AoR) = 𝑙 × 𝑏. 𝑙
𝑟
Answer 1: i not in ListB:
𝑏
Answer 2: ListB.append(i)
Answer :
Cities.append(item)
Answer 1: S.index("C")
Answer 1: Fact=FactList[-1]*i
Answer 2: S[IndexC+1:].count("M")
Answer 2: FactList.append(Fact)
Answer 3: IndexC+1+S[IndexC+1:].index("M")
CMPE-CMSE 107 Spring-2021/2022 Midterm Page 5
PART D: FILL IN BLANKS CODING QUESTIONS QD2) (12pts) Given the following algorithm, write the
corresponding Python program
QD1) (15pts) The following flowchart calculates and
lists the numbers that evenly divides input N, write Algorithm
the corresponding Python program according to the 1. Input A,B,C
flowchart. 2. Delta=B**2-4.0*A*C
Start 3. If Delta < 0:
a. Print(“No real roots”)
Input N
4. Else:
a. If Delta = 0
i=2 b. Print(“One real root: ”, -B/(2*A)
ListA= [ ]
c. Else:
d. Print(“Two real roots: “)
T e. Print(“Root1: “, (-B+Delta**0.5)/(2*A))
İf N%i ==0
f. Print(“Root2:”, (-B-Delta**0.5)/(2*A))
F ListA.append(i)
i=i+1
T F
İ < N//2 Print ListA
Stop