• Tidak ada hasil yang ditemukan

Mid-Term Exam 1 – Part 1 (MCQ)

N/A
N/A
Protected

Academic year: 2025

Membagikan "Mid-Term Exam 1 – Part 1 (MCQ)"

Copied!
65
0
0

Teks penuh

(1)

Sample Exam Questions

Mid-Term Exam 1 – Part 1 (MCQ)

CPIT 110 (Problem-Solving and Programming)

Version 1.0

(2)

هيبنت

!

2

راابتخا ةلئسأ ةقيرط حضوت طقف ةنيع نع ةرابع ةلئسلأا هذه • رلأا رروالا

- رلأا ءزجلا (

تارايتخلاا )

تلاكشملا لحر ةجمربلا ررقمل (

CPIT-110 .)

ةركاذملل اهيلع ومتعُي لا ةلئسلأا هذه • .

رابتخلال ةررقملا عيضاوملا عيمج ةلئسلأا هذه لمشت لا وق • .

لا ايبقتر ةركاذام نام ءااهتنلاا وعب ةعجارملل ةبسانم ةلئسلأا هذه • عياضاوم

رابتخلال ةررقملا .

ةلئسلأا ولح • ةقفرم

ةياهن فلملا اذه تاحفص

.

(3)

Question

#1

3

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

(4)

Question

#2

4

Which of the following code is correct?

a) // Comment b) /* Comment c) # Comment d) $$ Comment

Section 1.7 Programming Style and Documentation

(5)

Question

#3

5

Which of the following code is correct?

a) // comments //

b) /* comments */

c) ''' comments ''' d) /# comments #/

Section 1.7 Programming Style and Documentation

(6)

Question

#4

6

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

(7)

Question

#5

7

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

(8)

Question

#6

8

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

(9)

Question

#7

9

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

(10)

Question

#8

10

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

(11)

Question

#9

11

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

(12)

Question

#10

12

Which of the following is a valid identifier?

a) $343 b) mile c) 9X d) 8+9

Section 2.4 Identifiers

(13)

Question

#11

13

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

(14)

Question

#12

14

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

(15)

Question

#13

15

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

(16)

Question

#14

16

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

(17)

Question

#15

17

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

(18)

Question

#16

18

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

#17

19

What is the result of 3 // 2?

a) 1 b) 1.5 c) 2 d) 3

Section 2.8 Numeric Data Types and Operators

(20)

Question

#18

20

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

(21)

Question

#19

21

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

(22)

Question

#20

22

25 % 1 is _____

a) 1 b) 2 c) 3 d) 0

Section 2.8 Numeric Data Types and Operators

(23)

Question

#21

23

24 % 5 is _____

a) 1 b) 2 c) 4 d) 0

Section 2.8 Numeric Data Types and Operators

(24)

Question

#22

24

2 ** 3 evaluates to __________.

a) 9 b) 8 c) 9.0 d) 8.0

Section 2.8 Numeric Data Types and Operators

(25)

Question

#23

25

2 ** 3.0 evaluates to __________.

a) 9 b) 8 c) 9.0 d) 8.0

Section 2.8 Numeric Data Types and Operators

(26)

Question

#24

26

2 * 3 ** 2 evaluates to __________.

a) 36 b) 18 c) 12 d) 81

Section 2.8 Numeric Data Types and Operators

(27)

Question

#25

27

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

(28)

Question

#26

28

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

(29)

Question

#27

29

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

(30)

Question

#28

30

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

(31)

Question

#29

31

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

(32)

Question

#30

32

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

(33)

Question

#31

33

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

(34)

Question

#32

34

Suppose x is 1. What is x after x += 2?

a) 1 b) 2 c) 3 d) 4

Section 2.10 Augmented Assignment Operators

(35)

Question

#33

35

Suppose x is 1. What is x after x -= 1?

a) 0 b) 1 c) -1 d) 2

Section 2.10 Augmented Assignment Operators

(36)

Question

#34

36

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

(37)

Question

#35

37

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

(38)

Question

#36

38

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

(39)

Question

#37

39

What is max(3, 5, 1, 7, 4)?

a) 1 b) 3 c) 5 d) 7

Section 3.2 Common Python Functions

(40)

Question

#38

40

What is min(3, 5, 1, 7, 4)?

a) 1 b) 3 c) 5 d) 7

Section 3.2 Common Python Functions

(41)

Question

#39

41

What is round(3.52)?

a) 3.5 b) 3 c) 4 d) 2

Section 3.2 Common Python Functions

(42)

Question

#40

42

What is round(6.5)?

a) 4 b) 5 c) 6 d) 7

Section 3.2 Common Python Functions

(43)

Question

#41

43

What is round(7.5)?

a) 6 b) 7 c) 8 d) 5

Section 3.2 Common Python Functions

(44)

Question

#42

44

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

(45)

Question

#43

45

The expression "Good " + 1 + 2 + 3 evaluates to ________.

a) Good123 b) Good6

c) Good 123

d) Illegal expression

Section 3.3 Strings and Characters

(46)

Question

#44

46

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

(47)

Question

#45

47

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

(48)

Question

#46

48

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

(49)

Question

#47

49

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

(50)

Question

#48

50

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

(51)

Question

#49

51

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

(52)

Question

#50

52

The "less than or equal to" comparison operator is __________.

a) <<

b) <=

c) !=

d) >=

Section 4.2 Boolean Types, Values, and Expressions

(53)

Question

#51

53

The equal comparison operator is __________.

a) <>

b) !=

c) ==

d) =

Section 4.2 Boolean Types, Values, and Expressions

(54)

Question

#52

54

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

(55)

Question

#53

55

random.randint(0, 1) returns ____________.

a) 0 b) 1

c) 0 or 1 d) 2

Section 4.3 Generating Random Numbers

(56)

Question

#54

56

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

(57)

Question

#55

57

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

(58)

Question

#56

58

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

(59)

Question

#57

59

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

(60)

Question

#58

60

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

(61)

Question

#59

61

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

(62)

Question

#60

62

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

(63)

Solutions

63

Question # Correct Answer

1 B

2 C

3 C

4 D

5 A

6 B

7 B

8 D

9 B

10 B

Question # Correct Answer

11 B

12 D

13 D

14 D

15 C

16 B

17 A

18 A

19 D

20 D

(64)

Solutions

64

Question # Correct Answer

21 C

22 B

23 D

24 B

25 C

26 D

27 D

28 B

29 D

30 B

Question # Correct Answer

31 B

32 C

33 A

34 C

35 D

36 B

37 D

38 A

39 C

40 C

(65)

Solutions

65

Question # Correct Answer

41 C

42 B

43 D

44 C

45 A

46 B

47 D

48 C

49 C

50 B

Question # Correct Answer

51 C

52 A

53 C

54 B

55 C

56 B

57 C

58 B

59 B

60 C

Referensi

Dokumen terkait

The following statement which is true according to the text is….. Cire perdue not same with

equilateral. The negation is true. All real numbers are integers. The original statement is true. Some natural number is larger than its square. The original statement is true.

Statement B Aroha and Avaroha of Bhupali have ln the light of the above statements, choose the options given below: a Statement A is false, but Statement B is true.. correct answer

iWilliam Shakespeare’s career spanned the reign of Queen Elizabeth I ii William Shakespeare’s career spanned the reign of King James I A.. Only ii is true

ln the light of the above statements, choose the correct answer from the options given below: a Statement A is true, but Statement B is false... Raqas havinq Shuddha Re and Shuddha Dha

Model this situation as a Bayesian game and show that in any Nash equilibrium the highest prize that either individual is will- ing to exchange is the smallest possible prize.. 3

The correct statement that represents the relationship between x and y is: A When the number of hours he exercises decreases by 1 hour, his age decreases by 10.944 on average.. B When

T, F 4 Hydraulic conductivity of shale is typically a few orders larger than that of sandstone T,F 5 Peclet number expresses the transport of energy by bulk fluid motion to the energy