0% found this document useful (0 votes)
85 views12 pages

SE 100 Midterm 2 PDF

The document provides information about an exam for the SE 100 - Programming for Engineers course at Alfaisal University. It includes details such as the date, time, location, and percentage of the grade for the midterm exam. It lists the student name and number fields. It provides instructions for students, including allocating time wisely and showing work. It outlines the exam questions, learning outcomes assessed, and total marks. It includes two sample multiple choice questions and answers as examples of exam questions.

Uploaded by

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

SE 100 Midterm 2 PDF

The document provides information about an exam for the SE 100 - Programming for Engineers course at Alfaisal University. It includes details such as the date, time, location, and percentage of the grade for the midterm exam. It lists the student name and number fields. It provides instructions for students, including allocating time wisely and showing work. It outlines the exam questions, learning outcomes assessed, and total marks. It includes two sample multiple choice questions and answers as examples of exam questions.

Uploaded by

M.S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Alfaisal University - College of Engineering

Software Engineering Department

Subject: SE 100 – Programming for Engineers Midterm Exam #2 (Fall 2022)


FORM VERSION:
A/B/C/D
Instructor SE-100 Faculty
Date Wed, Dec 7, 2022 Time 18:00 AM – 20:00
Room Princess Haya Auditorium
Grade Percentage 20%

Student Name:

Student Number:

Student Signature:

Information and Instructions


➢ This is a closed book, closed notes exam. The University’s code of ethics applies.
➢ Allocate your time wisely.
➢ Answer each of the exam questions to the best of your knowledge.
➢ Clearly state any assumptions made that might be needed to understand your solution.
➢ Show your work – any sign of serious effort will be considered.
➢ No marks will be given for not making any effort.
Question Mark Full Course Learning Outcomes (CLO) Questions
Develop the computational thinking skill and
programming skills required to analyze problems and
1-36 3 108 CLO1 ALL
design algorithm to solve them programs and implement
these in Python
Learn basic components of Python as a high-level
CLO2 ALL
programming language
Gain experience in writing structured and modular
CLO3 ALL
computer programs.
Student analyze, evaluate and explain the planning and
execution of their work by discussing programming
CLO4 N/A
problem, bugs and modify them to create better alternate
solution.
Demonstrate the ability to think rationally, act ethically,
Total 100 CLO5 consistently and safely, with integrity and high moral ALL
standards in their professional endeavors.
Apply advanced computer skills to interpret their
CLO6 programs by leaving appropriate comments during N/A
algorithm analysis and design.
1) Which of the following loop(s) print(s) "Welcome to Python" 5 times?
A:
for count in range(5):
print("Welcome to Python")
B:
for count in range(0, 5, 1):
print("Welcome to Python")
C:
for count in range(1, 5):
print("Welcome to Python")
D:
for count in [0,1,2,3,4]:
print("Welcome to Python")

A. ABC
B. ABCD
C. C
D. ABD

2) _________ loop uses a true/false condition to control the number of times that it repeats.
A. Condition-controlled
B. Counted-controlled
C. Both condition-controlled and counted-controlled
D. None of the mentioned

3) What is the output of the following code (Consider the comma as a new line)?
START_SPEED = 60
END_SPEED = 101
INCREMENT = 10

print('KPH', end=', ')


for kph in range(START_SPEED, END_SPEED, INCREMENT):
print(kph, end=', ')

A. KPH, 60, 70, 80, 90, 100, 110,


B. KPH, 100, 90, 80, 70, 60,
C. KPH, 60, 70, 80, 90, 100,
D. KPH, 70, 80, 90, 100, 110,
E. KPH, 60, 70, 80, 90, 100, 110,

Page 2 of 12
4) What is the output of the following code if the user enters (Andrew) as the first name and (Ng) as
the last name?
x = 'i'
while x == 'i':
fname = input('Enter your first name: ')
lname = input('Enter your last name: ')
merge_names = fname + lname
print(merge_names)
print('End program')

A. AndrewNg
End program
B. AndrewNg, and then the program goes into an infinite loop.
C. Andrew Ng
D. Andrew Ng End program

5) What is the output of the following code?


i=1
j=3
while i< 3 and j>1:
print (i + j)
j-=2
i+=1

A. 4 7 11 14 … (continues adding 3 to infinity)


B. 4
C. 47
D. 7

6) How many times is the print statement in line 3 executed?


for i in range(0, 10):
for j in range(0, 5):
print(i * j)
A. 5
B. 10
C. 15
D. 50

7) What is the first negative index in a list?


A. 0
B. -0
C. -1
D. The size of the list
E. Negative the size of the list

Page 3 of 12
8) What will be displayed after the following code is executed?
for num in range(0, 20, 5):
num += num
print(num)

A. 25
B. 30
C. 0 5 10 15
D. The code will not work because of a syntax error

9) What is a possible output of the following code?


import random
print(random.randrange(2,10,2))

A. 2
B. 10
C. 12
D. 20

10) What is the output of the following code (Consider the comma as a new line)?
x = 1
def f1():
x = 3
print(x)

f1()
print(x)

A. 1, 1
B. 2, 3
C. 3, 3
D. 3, 1
E. Error

11) What will be displayed when the following code is run?


def func(a1,a2,a3=0,a4=2):
a = a1+a2+a3+a4
print(a)
func(1,2,1,2)

A. 3
B. 5
C. 6
D. 7
E. The program has a runtime error because a3 and a4 are not defined

Page 4 of 12
12) What is the output of the following code?
x = "hard"

def myfunc():
global x
x = "easy"

myfunc()
print("Python is " + x)

A. Python is hard
B. Python is easy
C. Python is hard easy
D. Python is easy hard
E. The program has a runtime error because x is not defined.

13) What is the output of the following code?


a = [1, 3, 5]
b = [2, 4, 6]
c = [10, 20, 30]
a = b + c
a[3] = 99
print(a)

A. [2, 4, 6, 10, 20, 30]


B. [1, 3, 5, 99, 20, 30]
C. Syntax error
D. [2, 4, 6, 99, 20, 30]

14) What is the output of the following code?


list1 = [1, 3, 2, 4, 5, 2, 1, 0]
print(list1[:-1])

A. [1, 3, 2, 4, 5, 2]
B. [1, 3, 2, 4, 5, 2, 1]
C. 0
D. [1, 3, 2, 4, 5, 2, 1, 0]

15) Suppose t = (1, 2, 4, 3), which of the following is an incorrect statement?


A. print(len(t))
B. print(max(t))
C. print(t[3])
D. t[3] = 45

Page 5 of 12
16) What is the output of the following code?
def f(i, values):
values.append(i)
return values
myList = []
v = f(1, myList)
v = f(2, myList)
v = f(3, myList)
print(v)

A. [1] [2] [3]


B. [1] [1, 2] [1, 2, 3]
C. 123
D. [1, 2, 3]

17) What is the output of the following code?


def f(aValue, aList):
aValue = 100
aList[0] = 44

myValue = 1
myList = [10, 20, 30]
f(myValue, myList)
print(myValue,',' ,myList)

A. 1 , [10, 20, 30]


B. 1 , [44, 20, 30]
C. 100 , [10, 20, 30]
D. 100 , [44, 20, 30]

18) What is the output of the following code (Consider the comma as a new line)?
def c(x):
x = 52
print('x is', x)
def main():
x = 42
print('x is', x)
c(x)
print('x is', x)
main()

A. x is 42, x is 52, x is 52
B. x is 42, x is 42, x is 42
C. x is 42, x is 52, x is 42
D. x is 52, x is 52, x is 52

Page 6 of 12
19) What is the output of the following code?
list1 = ['a', 'b', 'c']
list2 = ['A', 'B', 'C']
list1 += list2

print(list1)

A. ['a', 'b', 'c'] ['A', 'B', 'C']


B. ['a', 'b', 'c']
C. ['a', 'b', 'c', 'A', 'B', 'C']
D. ['A', 'B', 'C']
E. The += augmented assignment operator cannot be used with lists

20) What is the output of the following code?


number = 0
def main():
global number
number = 10
show_number(number)
def show_number(number):
print('The number is', number)
main()
print('The number is', number)

A. The number is 10
The number is 0
B. The number is 10
The number is 10
C. The number is 0
The number is 10
D. The number is 0
The number is 0

21) What is the output of the following code?


numbers = [1, 2, 3, 4, 5]
my_list = numbers[:]
my_list = numbers[:1]
my_list = numbers[1:]
my_list = numbers[-3:]
print(my_list)

A. [1, 2, 3, 4, 5]
B. [2, 3, 4, 5]
C. [3, 4, 5]
D. [1]

Page 7 of 12
22) What is the possible output after executing the following code?
import random
HEADS = 1
TAILS = 2
TOSSES = 10
def main():
for toss in range(TOSSES):
if random.randint(HEADS, TAILS) == HEADS:
print('Heads')
else:
print('Tails')
main()

A. It may print 10 times Heads


B. It may print 10 times Tails
C. It may print 3 times Heads and 7 times Tails
D. All answers of (A), (B), and (C) are correct.
E. It will print nothing on the console

23) What is the output of the following code?


x = [1, 2, 3]
x1 = [10, 20, 30]
x1 += x
print(x)
print(x1)

A. [1, 2, 3]
[1, 2, 3, 10, 20, 30]
B. [1, 2, 3]
[10, 20, 30, 1, 2, 3]
C. [1, 2, 3]
[10, 20, 30]
D. [10, 20, 30]
[1, 2, 3]

24) What is the correct answer for the following code?


s=9
while(s<10):
s+=1
print(s)

A. It will go into an infinite loop


B. It will print all numbers from 0 to 10
C. It will print number 11
D. It will print number 10

Page 8 of 12
25) What is the output of the following code?
lis = [2, 1, 3, 5, 3, 8]
lis.sort()
print ("List elements are : ", end="")
for i in range(0, len(lis)):
print(lis[i], end=" ")
lis.reverse()
lis.remove(3)
print ("\nList elements are : ", end="")
for i in range(0, len(lis)):
print(lis[i], end=" ")

A. List elements are : 1 2 3 3 5 8


List elements are : 8 5 3 2 1
B. List elements are : 1 2 3 3 5 8
List elements are : 8 5 3 3 2 1
C. List elements are : 1 2 3 3 5 8
List elements are : 8 5 3 3 1
D. List elements are : 1 2 3 3 5 8
List elements are : 8 5 2 1

26) What is the correct answer after executing the following code? (Consider the comma as a new
line)
s=0
while(s<10):
if(s%2==1):
print(s)
s+=1

A. It will print 1,3,5,7,9


B. It will print all integer numbers from 0 to 10
C. It will print number 10
D. It will go into an infinite loop
E. It will print only number 2

27) What is the output after executing the following code? (Consider the comma as a new line).
for x in range(2,11,2):
if(x%2==0):
print(x)

A. It will go into an infinite loop


B. It will print 2, 4, 6, 8
C. It will print 2, 4, 6, 8, 10
D. It will print 3, 5, 7, 9
E. It will print 2, 11, 2

Page 9 of 12
28) Given the following code, which of the following statement is a correct answer?
s=10
sum=0
while(s!=0):
s=int(input("Input: " ))
sum+=s
print("Sum is ", sum)

A. It will keep on showing the message “Input: ”,as the user keeps entering non-zero numbers. If
the input is zero, it will print the summary of the numbers.
B. It will show the message “Input: ”once, and after the user inputs a number will go into an
endless loop.
C. It will keep on showing the message “Input: ”, as the user keeps entering non- zero numbers.
If the input is zero, it will print the message “Sum is 0”.
D. It will keep on showing the message “Input: ”,as the user keeps entering non- zero numbers. If
the input is zero, it will go into an infinite loop.
E. It will show the message “Input: ” once, and after the user inputs a number it will print the
message “Sum is <Num>”, where <Num> is the user’s input.

29) What is the output of the following code?


for x in range(-5,5):
if(x!=4):
print(x)

A. It will print integer numbers from -5 to 4 and finish


B. It will print interger numbers from -5 to 5 excluding number 4 and finish
C. It will go into an infinite loop
D. It will print integer numbers from -5 to 3 and finish
E. It will print -5 and 4 only

30) What is the output of the following code? (Consider the comma as a new line).
s=0
for x in range(5):
s+=x
print(s)

A. Just number 10
B. 0,1,3,6
C. 0,5
D. 0,1,2,3,4
E. 0,1,3,6,10

Page 10 of 12
31) What is the output of the following code:
def aFunction(arg1, arg2, arg3):
for x in range(arg1,arg2):
arg3+=x
print(arg3)

aFunction(2,3,5)

A. 8
B. 10
C. There is no output, but the code will exit successfully
D. The code will go into an infinite loop
E. None of those answers is correct

32) What is the output of the following code? (Consider the comma as a new line)?
def changeValue(arg1, arg2, arg3):
print (arg2)
arg3 = 7
return arg1

arg3 = changeValue(2,4,5)
print(arg3)

A. 4, 7
B. 4, 2
C. Sytax error
D. 2, 7
E. 5

33) What is the output of the following code?


s=0
d=0
while(s<4):
s+=2
d-=s
print(d)

A. -8
B. 6
C. 4
D. d
E. -6

Page 11 of 12
34) Using the math module, what is the correct statement to find the square root of a number, x?
Assume that the math module is imported.
F. squareRoot(x)
G. math.sqrt(x)
H. M.SR(x)
I. MATH.sqrt(x)

35) What is the output of the following code?


aChar = 'A'

def change(list):
aChar = 'B'
list[2] = 99

fives = [5, 55, 555]


change(fives)
print(aChar,',',fives)

E. A , [5, 55, 99]


F. B , [5, 55, 99]
G. A , [5, 55, 555]
H. B , [5, 55, 555]

36) What is the output of the following code?


def sort(number1, number2):
if number1 < number2:
return number1, number2
else:
return number2, number1

n1, n2 = sort(77, 55)


print(n1,', ', n2)

A. Syntax error since the function cannot return more than one value
B. 77 , 55
C. 55 , 77
D. 77 , 77
E. 55 , 55

Page 12 of 12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy