CPIT110 - (Test for ALL CHAPTERS 1-4)

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/76

flashcard set

Earn XP

Description and Tags

Study as a Practice Test

77 Terms

1
New cards

Which of the following codes 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”)

print(“Programming is fun”)

print(“Python is fun”)

2
New cards

Which of the following code is correct?

a) //comment

b) /* comment

c) # comment
d) $$ comment

#comment

3
New cards

Which of the following code is correct?

a) // comments //
b) /* comments */
c) ''' comments '''
d) /# comments #/

''' comments '''

4
New cards

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")

print("Programming is fun")

print("Python")

print("Computer Science")

5
New cards

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"))

input("Enter a string")

6
New cards

What is the result of eval("1 + 3 * 2")?

7

7
New cards

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)

2.0

8
New cards

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)

The program will have a runtime error on the input.

9
New cards

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.

\

10
New cards

Which of the following is a valid identifier?

mile

11
New cards

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)

2

12
New cards

What will be displayed by the following code?

x = 1

x = 2 * x + 1

print(x)

3

13
New cards

What will be displayed by the following code?

x = 1

x = x + 2.5

print(x)

3.5

14
New cards

What will be displayed by the following code?

x, y = 1, 2

x, y = y, x

print(x, y)

2, 1

15
New cards

To following code reads two number. Which of the following is the correct input for the code?

x, y = eval(input("Enter two numbers: "))

1, 2

16
New cards

What is the result of 3 / 2?

1.5

17
New cards

What is the result of 3 // 2?

1

18
New cards

Which of the following expressions will yield 0.5?

1 / 2

19
New cards

Which of the following expression results in a value 1?

2 % 1

20
New cards

25 % 1 is _____

0

21
New cards

24 % 5 is _____

4

22
New cards

2 ** 3 evaluates to __________.

8.0

23
New cards

2 3 * 2 evaluates to __________.

18

24
New cards

What is y displayed in the following code?

x = 1

y = x = x + 1

print("y is" , y)

y is 2 because x + 1 is assigned to x and then x is assigned to y

25
New cards

What is the result of evaluating 2 + 2 ** 3 / 2?

6.0

26
New cards

What is the value of i printed?

j = i = 1

i += j + j * 5

print("What is i?", i)

7

27
New cards

What is x after the following statements?

x = 1

x *= x + 1

x is 2

28
New cards

What is x after the following statements?

x = 2

y = 1

x *= y + 1

x is 4

29
New cards

To add a value 1 to variable x, you write:

x += 1

30
New cards

Which of the following statements are the same?

(A) x -= x + 4

(B) x = x + 4 - x

(C) x = x - (x + 4)

(A) and (C) are the same

31
New cards

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

3

32
New cards

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

0

33
New cards

What is x after the following statements?

x = 1

y = 2

x *= y + 1

x is 3

34
New cards

Which of the following functions returns 4?

round(3.9)

35
New cards

Which of the following functions cause an error?

eval("3.4")

36
New cards

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

10

37
New cards

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

1

38
New cards

What is round(3.52)?

4

39
New cards

What is round(6.5)?

6

40
New cards

What is round(7.5)?

8

41
New cards

Which of the following statement prints smith\exam1\test.txt?

print("smith\\exam1\\test.txt")

42
New cards

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

Illegal expression

43
New cards

What will be displayed by the following code?

print("A", end = ' ')

print("B", end = ' ')

print("C", end = ' ')

print("D", end = ' ')

A B C D

44
New cards

To format a number x to 3 digits after the decimal point, use:

format(x, "5.3f")

45
New cards

Suppose x is 345.3546, what is format(x, "10.3f")?

(note b represents a blank space)

bbb345.355

46
New cards

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"))

Welcome???#?111#924.66

47
New cards

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"))

???Welcome#111?#????924.66

48
New cards

Suppse ‘number’ contains integer value 4, which of the following statement is correct?

print(format(number, "2d"), format(number ** 1.5, "4.2f"))

49
New cards

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

<=

50
New cards

The equal comparison operator is __________.

==

51
New cards

To generate a random integer between 0 and 5, use ______.

random.randint(0, 5)

52
New cards

random.randint(0, 1) returns ____________.

0 or 1

53
New cards

random.random() returns ____________.

a float number i such that 0 <= i < 1.0

54
New cards

Which of the following code displays the area of a circle if the radius is positive.

if radius > 0: print(radius * radius *3.14159)

55
New cards

What is the output of the following code?

x = 0

if x < 4:

x = x + 1

print("x is", x)

x is 1

56
New cards

Suppose isPrime is a boolean variable, which of the following is the correct statement for testing if isPrime is true.

if isPrime:

57
New cards

Analyze the following code:

even = False

if even = True:

print("It is even!")

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:.

58
New cards

Analyze the following code:

even = False

if even:

print("It is even!")

The code displays nothing.

59
New cards

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=" ")

*** 2 $$$ 2

60
New cards

The following code displays ___________.

temperature = 50

if temperature >= 100:

print("too hot")

else:

print("just right")

just right

61
New cards

Suppose x = 1, y = -1, and z = 1. What will be displayed by the following statement?

if x > 0:

if y > 0:

print("x > 0 and y > 0")

elif z > 0:

print("x < 0 and z > 0")

Nothing displayed

62
New cards

Suppose income is 4001, what will be displayed by f the following code? if income > 3000:

print("Income is greater than 3000")

elif income > 4000:

print("Income is greater than 4000")

Income is greater than 3000

63
New cards

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is correct?

I:

if age < 16:

print("Cannot get a driver's license")

if age >= 16:

print("Can get a driver's license")

II:

if age < 16:

print("Cannot get a driver's license") \

else:

print("Can get a driver's license")

III:

if age < 16:

print("Cannot get a driver's license")

elif age >= 16:

print("Can get a driver's license")

IV:

if age < 16:

print("Cannot get a driver's license")

elif age == 16:

print("Can get a driver's license")

elif age > 16:

print("Can get a driver's license")

All correct

64
New cards

Analyze the following code:

Code 1:

if number % 2 == 0:

even = True

else:

even = False

Code 2:

even = number % 2 == 0

Both Code 1 and Code 2 are correct, but Code 2 is better

65
New cards

Which of the Boolean expressions below is incorrect?

!(x > 0) and (x > 0)

66
New cards

Which of the Boolean expressions below is incorrect?

True and 3 => 4

67
New cards

Given |x - 2| <= 4, Which of the following is true?

x - 2 <= 4 and x - 2 >= -4

68
New cards

Given |x - 2| >= 4, Which of the following is true?

x - 2 >= 4 or x - 2 <= -4

69
New cards

Assume x = 4 and y = 5, Which of the following is true?

x < 5 or y < 5

70
New cards

Assume x = 4 and y = 5, Which of the following is true?

x != 5

71
New cards

Which of the following is equivalent to x != y?

not (x == y)

72
New cards

What is y after the following statement is executed?
x = 0

y = 10

if x > 0

else -10

-10

73
New cards

What will be displayed by the following code? isCorrect = False print("Correct" if isCorrect else "Incorrect")

Incorrect

74
New cards

The order of the precedence (from high to low) of the operators +, *, and, or is:

*, +, and, or

75
New cards

Which of the following operators are right-associative.

=

76
New cards

What is the value of the following expression? True or True and False

True

77
New cards

Which of the following statements are True?

(x > 0 or x < 10 and y < 0) is same as (x > 0 or (x < 10 and y < 0))