0% found this document useful (0 votes)
16 views5 pages

Exam 3

This is an exam for an introduction to computer science course. The exam contains multiple choice and coding questions covering topics like loops, functions, lists, and basic Python concepts. The multiple choice questions cover topics like variable assignment, conditionals, loops, functions and parameters. The coding questions involve writing small programs to print sequences, take user input, and solve a quadratic equation with error checking.

Uploaded by

Lina Zaqout
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)
16 views5 pages

Exam 3

This is an exam for an introduction to computer science course. The exam contains multiple choice and coding questions covering topics like loops, functions, lists, and basic Python concepts. The multiple choice questions cover topics like variable assignment, conditionals, loops, functions and parameters. The coding questions involve writing small programs to print sequences, take user input, and solve a quadratic equation with error checking.

Uploaded by

Lina Zaqout
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/ 5

‫مقدمة في الحاسبات عملي‬: ‫اسم المساق‬ : ‫اسن الطالب‬

(LNGG 1003)
‫ ساعتان‬:‫مدة االمتحان‬ :‫الرقن الجاهعي‬
9:11 – 09:11 :‫وقت االهتحاى‬ :‫اسن الوعيد‬
‫االهتحاى النهائي للفصل األول‬
‫ م‬9191-9102 : ‫رقن الشعبة‬
Q1) Choose the correct answer

1)What will be displayed by the following code?


x, y = 1,2
x, y = y, x
print(y, x)
1 1 2 2 2 1 1 2
2) What is y after the following statement is executed?
x = 0
y = 10 if x > 0 else -10
-10 0 10 wrong expression
3) What is x after the following statements?
x = 1
x *= x + 1
1
3 1 2 3 4
4) What will be displayed when the following code is executed?
number = 6
while number > 0:
number -= 3
print(number)
63 630 30 3 0 -3

5) An identifier can contain digits, but cannot start with a digit?


True False

6) The function range(1,5) return a sequence ______________.

1, 2, 3, 4, 5 0, 1, 2, 3, 4, 5 0, 1, 2, 3, 4, 5 1, 2, 3, 4
7) Which of the following function is incorrect? (choose multiple)

range(0, 3.5) range(10, 4, -1) range(1, 3, 1) range(2.5, 4.5)


8) Given the following function
def nPrint(message, n):
while n > 0:
print(message)
n -= 1
What will be displayed by the call nPrint('a', 4)?
aaaa Aaa invalid call infinite loop
9) What is the output for y ?
for i in range(0, 10, 2):
y += i
print(y)

10 11 17 20
10) What is the output of the following code?
x = 0
while x < 4:
x = x + 1
print("x is", x)
x is 2 x is 4 x is 5
X is 0
11) What is sum after the following loop terminates?

sum = 0
item = 0
while item < 5:
item += 1
sum += item
if sum >= 4:
continue

print(sum)
15 16 17 18

12) How many times is the print statement executed?


for i in range(5):
for j in range(i):
i += j
print i
100 10 20 45
13) Consider the following incomplete code:
def f(number):
# Missing function body

print(f(5))
The missing function body should be ________.
print(number) return "number" print("number") return number

14) A variable defined inside a function is referred to as __________.

a function variable a global variable block variable a local variable


15) What will be displayed by the following code?
x = 1
def f1():
y = x + 2
print(y)

f1()
print(x)
1 3 3 1 1 1 3 3
Q2) what is printed by the Python code?

Input Output
for z in [2, 4, 7, 9]:
print(z - 1)

n = 3
for x in [2, 5, 8]:
n = n + x
print(n)
def func(x):
return x – 1
print(func(3) * func(5))

words = ['A', 'short', 'list']


print(len(words))
for s in words:
print(len(s))
Q3) Write a program that prints all numbers from 0 to 100 except the division by 7.

Q4) Write program that let you enter 10 positive numbers, but if you enter a negative
number it quit.
Q5) Write a Python program to solve quadratic equations of the form 𝑎 +𝑏 +𝑐=0
Where the coefficients a, b, and c are real numbers taken from user. The two real
number solutions are derived by the formula

For this exercise, you MUST CHECK THAT a ≠ 0 and 𝑏 ≥ 4𝑎𝑐

Q6) Write a function that takes a list and returns the first negative number.

Good Luck 

You might also like