0% found this document useful (0 votes)
92 views65 pages

Mid-Term Exam 1 - Part 1 (MCQ)

This document provides a sample exam for a mid-term exam on a problem-solving and programming course (CPIT 110). It includes 30 multiple choice questions covering various topics in Python programming like variables, input/output, operators, and expressions. The questions are intended to illustrate the style of questions that may appear on the exam but do not cover all topics or serve as a study guide. Solutions are provided at the end.
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)
92 views65 pages

Mid-Term Exam 1 - Part 1 (MCQ)

This document provides a sample exam for a mid-term exam on a problem-solving and programming course (CPIT 110). It includes 30 multiple choice questions covering various topics in Python programming like variables, input/output, operators, and expressions. The questions are intended to illustrate the style of questions that may appear on the exam but do not cover all topics or serve as a study guide. Solutions are provided at the end.
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/ 65

Sample Exam Questions

Mid-Term Exam 1 – Part 1 (MCQ)


CPIT 110 (Problem-Solving and Programming)

Version 1.0
‫تنبيه!‬
‫• هذه األسئلة عبارة عن عينة فقط توضح طريقة أسئلة اختباار الاورر األر‬
‫‪ -‬الجزء األر (االختيارات) لمقرر البرمجة رحل المشكالت (‪.)CPIT-110‬‬
‫• هذه األسئلة ال ُيعتمو عليها للمذا كرة‪.‬‬
‫• قو ال تشمل هذه األسئلة جميع المواضيع المقررة لالختبار‪.‬‬
‫• هذه األسئلة مناسبة للمراجعة بعو االنتهااء مان ماذا كرة رتقبيا المواضايع‬
‫المقررة لالختبار‪.‬‬
‫• حلو األسئلة مرفقة نهاية صفحات هذا الملف‪.‬‬

‫‪2‬‬
Question
#1
Which of the following code is correct?
a) print("Programming is fun")
print("Python is fun")
b) print("Programming is fun")
print("Python is fun")
c) print("Programming is fun)
print("Python is fun")
d) print("Programming is fun)
print("Python is fun")

Section 1.6 Getting Started with Python 3


Question
#2
Which of the following code is correct?
a) // Comment
b) /* Comment
c) # Comment
d) $$ Comment

Section 1.7 Programming Style and Documentation 4


Question
#3
Which of the following code is correct?
a) // comments //
b) /* comments */
c) ''' comments '''
d) /# comments #/

Section 1.7 Programming Style and Documentation 5


Question
#4
Which of the following code is correct?
a) print("Programming is fun")
print("Python")
print("Computer Science")
b) print("Programming is fun")
print("Python")
print("Computer Science")
c) print("Programming is fun")
print("Python")
print("Computer Science")
d) print("Programming is fun")
print("Python")
print("Computer Science")

Section 1.8 Programming Errors 6


Question
#5
What function do you use to read a string?
a) input("Enter a string")
b) eval(input("Enter a string"))
c) enter("Enter a string")
d) eval(enter("Enter a string"))

Section 2.3 Reading Input from the Console 7


Question
#6
What is the result of eval("1 + 3 * 2")?
a) "1 + 3 * 2"
b) 7
c) 8
d) "1 + 6"

Section 2.3 Reading Input from the Console 8


Question
#7
If you enter 1 2 3 in three separate lines, when you run this program, what will be displayed?
print("Enter three numbers: ")
number1 = eval(input())
number2 = eval(input())
number3 = eval(input())
# Compute average
average = (number1 + number2 + number3) / 3
# Display result
print(average)

a) 1.0
b) 2.0
c) 3.0
d) 4.0

Section 2.3 Reading Input from the Console 9


Question
#8
If you enter 1 2 3 in one line, when you run this program, what will be displayed?
print("Enter three numbers: ")
number1 = eval(input())
number2 = eval(input())
number3 = eval(input())

# Compute average
average = (number1 + number2 + number3) / 3

# Display result
print(average)
a) The program runs correctly and displays 1.0
b) The program runs correctly and displays 2.0
c) The program runs correctly and displays 3.0
d) The program will have a runtime error on the input.

Section 2.3 Reading Input from the Console 10


Question
#9
You can place the line continuation symbol __ at the end of a line
to tell the interpreter that the statement is continued on the next
line.
a) /
b) \
c) #
d) &

Section 2.3 Reading Input from the Console 11


Question
#10
Which of the following is a valid identifier?
a) $343
b) mile
c) 9X
d) 8+9

Section 2.4 Identifiers 12


Question
#11
If you enter 1, 2, 3, in one line, when you run this program, what will
be displayed?
number1, number2, number3 = eval(input("Enter three
numbers: "))
# Compute average
average = (number1 + number2 + number3) / 3
# Display result
print(average)
a) 1.0
b) 2.0
c) 3.0
d) 4.0

Section 2.5 Variables, Assignment Statements, and Expressions 13


Question
#12
What will be displayed by the following code?
x = 1
x = 2 * x + 1
print(x)
a) 0
b) 1
c) 2
d) 3

Section 2.5 Variables, Assignment Statements, and Expressions 14


Question
#13
What will be displayed by the following code?
x = 1
x = x + 2.5
print(x)
a) 1
b) 2
c) 3
d) 3.5

Section 2.5 Variables, Assignment Statements, and Expressions 15


Question
#14
What will be displayed by the following code?
x, y = 1, 2
x, y = y, x
print(x, y)
a) 1 1
b) 2 2
c) 1 2
d) 2 1

Section 2.6 Simultaneous Assignments 16


Question
#15
To following code reads two number. Which of the following is
the correct input for the code?
x, y = eval(input("Enter two numbers: "))
a) 1 2
b) "1 2"
c) 1, 2
d) 1, 2,

Section 2.6 Simultaneous Assignments 17


Question
#16
What is the result of 3 / 2?
a) 1
b) 1.5
c) 2
d) 3

Section 2.8 Numeric Data Types and Operators 18


Question
#17
What is the result of 3 // 2?
a) 1
b) 1.5
c) 2
d) 3

Section 2.8 Numeric Data Types and Operators 19


Question
#18
Which of the following expressions will yield 0.5?
a) 1 / 2
b) 1 // 2
c) 1.0 // 2
d) 2 / 2

Section 2.8 Numeric Data Types and Operators 20


Question
#19
Which of the following expression results in a value 1?
a) 2 % 1
b) 15 % 4
c) 25 % 5
d) 3 % 2

Section 2.8 Numeric Data Types and Operators 21


Question
#20
25 % 1 is _____
a) 1
b) 2
c) 3
d) 0

Section 2.8 Numeric Data Types and Operators 22


Question
#21
24 % 5 is _____
a) 1
b) 2
c) 4
d) 0

Section 2.8 Numeric Data Types and Operators 23


Question
#22
2 ** 3 evaluates to __________.
a) 9
b) 8
c) 9.0
d) 8.0

Section 2.8 Numeric Data Types and Operators 24


Question
#23
2 ** 3.0 evaluates to __________.
a) 9
b) 8
c) 9.0
d) 8.0

Section 2.8 Numeric Data Types and Operators 25


Question
#24
2 * 3 ** 2 evaluates to __________.
a) 36
b) 18
c) 12
d) 81

Section 2.8 Numeric Data Types and Operators 26


Question
#25
What is y displayed in the following code?
x = 1
y = x = x + 1
print("y is", y)
a) y is 0.
b) y is 1 because x is assigned to y first.
c) y is 2 because x + 1 is assigned to x and
then x is assigned to y.
d) The program has a compile error since x
is redeclared in the statement int y = x
= x + 1.
Section 2.8 Numeric Data Types and Operators 27
Question
#26
What is the result of evaluating 2 + 2 ** 3 / 2?
a) 4
b) 6
c) 4.0
d) 6.0

Section 2.9 Evaluating Expressions and Operator Precedence 28


Question
#27
What is the value of i printed?
j = i = 1
i += j + j * 5
print("What is i?", i)
a) 1
b) 5
c) 6
d) 7

Section 2.10 Augmented Assignment Operators 29


Question
#28
What is x after the following statements?
x = 1
x *= x + 1
a) x is 1
b) x is 2
c) x is 3
d) x is 4

Section 2.10 Augmented Assignment Operators 30


Question
#29
What is x after the following statements?
x = 2
y = 1
x *= y + 1
a) x is 1
b) x is 2
c) x is 3
d) x is 4

Section 2.10 Augmented Assignment Operators 31


Question
#30
To add a value 1 to variable x, you write
a) 1 + x = x
b) x += 1
c) x := 1
d) x =+ 1

Section 2.10 Augmented Assignment Operators 32


Question
#31
Which of the following statements are the same?
(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)
a) (A) and (B) are the same
b) (A) and (C) are the same
c) (B) and (C) are the same
d) (A), (B), and (C) are the same

Section 2.10 Augmented Assignment Operators 33


Question
#32
Suppose x is 1. What is x after x += 2?
a) 1
b) 2
c) 3
d) 4

Section 2.10 Augmented Assignment Operators 34


Question
#33
Suppose x is 1. What is x after x -= 1?
a) 0
b) 1
c) -1
d) 2

Section 2.10 Augmented Assignment Operators 35


Question
#34
What is x after the following statements?
x = 1
y = 2
x *= y + 1
a) x is 1
b) x is 2
c) x is 3
d) x is 4

Section 2.10 Augmented Assignment Operators 36


Question
#35
Which of the following functions return 4.
a) int(3.4)
b) int(3.9)
c) round(3.4)
d) round(3.9)

Section 2.11 Type Conversions and Rounding 37


Question
#36
Which of the following functions cause an error?
a) int("034")
b) eval("034")
c) int(3.4)
d) eval("3.4")

Section 2.11 Type Conversions and Rounding 38


Question
#37
What is max(3, 5, 1, 7, 4)?
a) 1
b) 3
c) 5
d) 7

Section 3.2 Common Python Functions 39


Question
#38
What is min(3, 5, 1, 7, 4)?
a) 1
b) 3
c) 5
d) 7

Section 3.2 Common Python Functions 40


Question
#39
What is round(3.52)?
a) 3.5
b) 3
c) 4
d) 2

Section 3.2 Common Python Functions 41


Question
#40
What is round(6.5)?
a) 4
b) 5
c) 6
d) 7

Section 3.2 Common Python Functions 42


Question
#41
What is round(7.5)?
a) 6
b) 7
c) 8
d) 5

Section 3.2 Common Python Functions 43


Question
#42
Which of the following statement prints smith\exam1\test.txt?
a) print("smith\exam1\test.txt")
b) print("smith\\exam1\\test.txt")
c) print("smith\"exam1\"test.txt")
d) print("smith"\exam1"\test.txt")

Section 3.3 Strings and Characters 44


Question
#43
The expression "Good " + 1 + 2 + 3 evaluates to ________.
a) Good123
b) Good6
c) Good 123
d) Illegal expression

Section 3.3 Strings and Characters 45


Question
#44
What will be displayed by the following code?
print("A", end = ' ')
print("B", end = ' ')
print("C", end = ' ')
print("D", end = ' ')
a) ABCD
b) A, B, C, D
c) A B C D
d) A, B, C, D will be displayed on four lines

Section 3.3 Strings and Characters 46


Question
#45
To format a number x to 3 digits after the decimal point, use:
a) format(x, "5.3f")
b) format("5.3f", x)
c) format(x, "5.4f")
d) format("5.3f", x)

Section 3.6 Formatting Numbers and Strings 47


Question
#46
Suppose x is 345.3546, what is format(x, "10.3f")? (note b
represents a blank space)
a) bb345.355
b) bbb345.355
c) bbbb345.355
d) bbb345.354

Section 3.6 Formatting Numbers and Strings 48


Question
#47
What will be displayed by the following code? ? (note ?
represents a blank space)
print(format("Welcome", "10s"), end = '#')
print(format(111, "4d"), end = '#')
print(format(924.656, "3.2f"))
a) ???Welcome#?111#924.66
b) Welcome#111#924.66
c) Welcome#111#.66
d) Welcome???#?111#924.66

Section 3.6 Formatting Numbers and Strings 49


Question
#48
What will be displayed by the following code? ? (note ?
represents a blank space)
print(format("Welcome", ">10s"), end = '#')
print(format(111, "<4d"), end = '#')
print(format(924.656, ">10.2f"))
a) ???Welcome#?111#924.66
b) ???Welcome#?111#????924.66
c) ???Welcome#111?#????924.66
d) Welcome???#111?#????924.66

Section 3.6 Formatting Numbers and Strings 50


Question
#49
Suppse number contains integer value 4, which of the following
statement is correct?
a) print(format(number, "2d"), format(number ** 1.5, "4d"))
b) print(format(number, "2d"), format(number ** 1.5, "4.2d"))
c) print(format(number, "2d"), format(number ** 1.5, "4.2f"))
d) print(format(number, "2d"), format(number ** 1.5, "4.2s"))

Section 3.6 Formatting Numbers and Strings 51


Question
#50
The "less than or equal to" comparison operator is __________.
a) <<
b) <=
c) !=
d) >=

Section 4.2 Boolean Types, Values, and Expressions 52


Question
#51
The equal comparison operator is __________.
a) <>
b) !=
c) ==
d) =

Section 4.2 Boolean Types, Values, and Expressions 53


Question
#52
To generate a random integer between 0 and 5, use ______.
a) random.randint(0, 5)
b) random.randint(0, 6)
c) random.randint(1, 5)
d) random.randrange(0, 5)

Section 4.3 Generating Random Numbers 54


Question
#53
random.randint(0, 1) returns ____________.
a) 0
b) 1
c) 0 or 1
d) 2

Section 4.3 Generating Random Numbers 55


Question
#54
random.random() returns ____________.
a) a float number i such that 0 < i < 1.0
b) a float number i such that 0 <= i < 1.0
c) a float number i such that 0 <= i <= 1.0
d) a float number i such that 0 < i < 2.0

Section 4.3 Generating Random Numbers 56


Question
#55
Which of the following code displays the area of a circle if the
radius is positive.
a) if radius != 0: print(radius * radius * 3.14159)
b) if radius >= 0: print(radius * radius * 3.14159)
c) if radius > 0: print(radius * radius * 3.14159)
d) if radius <= 0: print(radius * radius * 3.14159)

Sections 4.4 if Statements 57


Question
#56
What is the output of the following code?
x = 0
if x < 4:
x = x + 1

print("x is", x)
a) x is 0
b) x is 1
c) x is 2
d) x is 3

Sections 4.4 if Statements 58


Question
#57
Suppose isPrime is a boolean variable, which of the following is
the correct statement for testing if isPrime is true.
a) if isPrime = True:
b) if isPrime == TRUE:
c) if isPrime:
d) if not isPrime = False:

Sections 4.4 if Statements 59


Question
#58
Analyze the following code:
even = False
if even = True:
print("It is even!")
a) The program has a syntax error in line 1 (even = False)
b) The program has a syntax error in line 2 if even = True is
not a correct condition. It should be replaced by if even ==
True: or if even:.
c) The program runs, but displays nothing.
d) The program runs and displays It is even!.

Sections 4.4 if Statements 60


Question
#59
Analyze the following code:
even = False
if even:
print("It is even!")
a) The code displays It is even!
b) The code displays nothing.
c) The code is wrong. You should replace if
even: with if even == True:
d) The code is wrong. You should replace if
even: with if even = True:

Sections 4.4 if Statements 61


Question
#60
Suppose x = 1, y = 2, and z = 1. What will be displayed by the
following statement?
if x > 0:
print("***", y, end=" ")
if z > 0:
print("$$$", y, end=" ")
a) *** 2
b) $$$ 2
c) *** 2 $$$ 2
d) *** $$$

Sections 4.4 if Statements 62


Solutions
Question # Correct Answer Question # Correct Answer
1 B 11 B
2 C 12 D
3 C 13 D
4 D 14 D
5 A 15 C
6 B 16 B
7 B 17 A
8 D 18 A
9 B 19 D
10 B 20 D

63
Solutions
Question # Correct Answer Question # Correct Answer
21 C 31 B
22 B 32 C
23 D 33 A
24 B 34 C
25 C 35 D
26 D 36 B
27 D 37 D
28 B 38 A
29 D 39 C
30 B 40 C

64
Solutions
Question # Correct Answer Question # Correct Answer
41 C 51 C
42 B 52 A
43 D 53 C
44 C 54 B
45 A 55 C
46 B 56 B
47 D 57 C
48 C 58 B
49 C 59 B
50 B 60 C

65

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