MIS 207 exam 1 quizzes
What is displayed by the following code segment? print("\"Hello World!\"")
"Hello World!"
Consider the following code segment: x = 5 y = 7 z = x - y * 2 After this code segment executes, the value of z is:
-9
What will be printed by the statements below? for ctr in range(0, 10) : print(ctr, end = " ")
0 1 2 3 4 5 6 7 8 9
What is the output of the code snippet given below? n = 0 while n * n < 100 : print(n * n, end = " ") n = n + 1
0 1 4 9 16 25 36 49 64 81
What is the output of the code snippet given below? i = 0 while i != 9 : print(i, end = " ") i = i + 2
0 2 4 6 8 10 12 14 ... (infinite loop)
What is the output of the code snippet given below? i = 0 while i != 11 : print(i, end=" ") i = i + 3
0 3 6 9 12 ... (infinite loop)
Consider the following code segment: c = 2 b = 1 if b == 0 : c = c + 1 else : c = c - 1 print(c) What value is printed by this code segment?
1
Consider the following code segment: numPizzas = 1 numPeople = 4 if numPeople == 5 : numPizzas = 2 After this code segment executes, what value is in the variable numPizzas?
1
What will be printed by the following code snippet? name = "Ravi Avalon" counter = name.count("av") print(counter)
1
How many times does the following loop run? i = 0 j = 1 while j >= 1 : print("" , i , ";" , j) i = j + 1 if i % 2 == 0 : j = j - 1
1 time
What is printed by the following code snippet? print(25 + 84)
109
What is the output of the following code snippet? num1 = 100 if num1 < 100 : if num1 < 50 : num1 = num1 - 5 else : num1 = num1 - 10 else : if num1 > 150 : num1 = num1 + 5 else : num1 = num1 + 10 print(num1)
110
Consider the following code segment: x = 5 y = 3 z = 2 result = x // y + x % z After this code segment, the value of result is:
2
What is the output of this code snippet? s = 1 n = 1 while s < 3 * n : s = s + n print(s , end = " ") n = n + 1
2 4 7 11 16 22
What is printed by the following code snippet? print("25 + 84")
25 + 84
What is the output of this code snippet? str = "ABCabc" i = 0 while i < len(str) : ch = str[i] if ch.islower() : print(i , " ") else : i = i + 1
3 3 3 3 3 ... (infinite loop)
Assume the following variable has been declared and given a value as shown: from random import randint number = randint(0, 27) * 2 + 3 What are the smallest and largest values that may be assigned to number?
3,57
Assume the following variable has been declared and given a value as shown: from random import random number = random() * 2 + 3 What are the smallest and largest values that may be assigned to number?
3.0, 5.0 (excluding 5.0)
What is returned by the function: round(3.14159, 2)?
3.14
What is the output of the following code snippet if the input is 34? number = int(input("Please enter a number: ")) if number != 20 : number = number + 1 else : number = number - 1 print(number)
35
Consider the following code segment: if count > 0 : x = x + 1 print(x) If count is initialized to -1 and x is initialized to 4 then the value displayed by this code segment is:
4
In the following code snippet, how many times will "Hello" be printed? for i in range(0, 10) : f or j in range(1, 5) : print("Hello")
40
Assuming that the user enters a value of 45, what is the output of the following code snippet? number = int(input("Please enter a number: ")) if number < 100 : number = number + 5 if number < 500 : number = number - 2 if number > 15 : number = number + 1 else : number = number - 1 print(number)
49
Assuming a user enters 30, 55, and 10 as the input, what is the output of the following code snippet? num1 = int(input("Enter a number: ")) num2 = int(input("Enter a number: ")) num3 = int(input("Enter a number: ")) if num1 > num2 and num1 > num3 : print(num1) elif num2 > num1 and num2 > num3 : print(num2) elif num3 > num1 and num3 > num2 : print(num3)
55
What is the value of 4 ** 3?
64
What is the value of the variable num after the following code snippet? num = 5 num2 = 6 num = num2 + 3
9
What are the two parts of an if statement?
A condition and a body
Suppose you must design a program to calculate the roll-out (number of inches traveled in one revolution of the pedals of a bicycle based on its gear combinations). The user must provide the gear sizes, which must be converted into roll-out for all different gear combinations. How can the flow of user interaction for this problem be designed?
A storyboard can be used
A sequence of characters enclosed in quotes is called:
A string
Suppose that a program asks a user to enter multiple integers, either positive or negative, to do some calculation. The data entry will stop when the user enters a certain value to indicate the end of the data. What value should the code use as the sentinel?
An alphabetic character
An integrated development environment bundles tools for programming into a unified application. What kinds of tools are usually included?
An editor and an interpreter
Given the following list of strings, what is the correct order using lexicographic ordering: "Ann", "amy", "Heather", "hanna", "joe", "john", "Leo", "Jim" ?
Ann, Heather, Jim, Leo, amy, hanna, joe, john
What is the wrong with the following code snippet? grade = int(input("Enter student grade: ")) if grade >= 90 : letterGrade = "A" if grade >= 80 : letterGrade = "B" if grade >= 70 : letterGrade = "C" if grade >= 60 : letterGrade = "D" else : letterGrade = "E" print(letterGrade)
Anyone with a grade higher than 60 will receive a "D"
When a function is called, the values placed in parentheses are referred to as:
Arguments
What will be the range of the random numbers generated by the following code snippet? from random import randint randomNum = randint(1,50)
Between 1 and 50
Consider the following code snippet: number = int(input("Enter a number: ")) if number < 10 : print("Too small") elif number < 50 : print("Intermediate") elif number < 100 : print("High") else : print("Too high") Assuming that the user input is 60, what is the output of the this code snippet?
High
What type of chart shows the distribution of data across a fixed number of categories?
Histogram
Which of the following activities can be simulated using a computer? I. Waiting time in a line at a restaurant II. Tossing a coin III. Shuffling cards for a card game
I, II, and III
What reads Python programs and executes the program instructions?
Interpreter
In Python, which of the following orderings is used to compare strings?
Lexicographic
Which line in the following program is a comment line? 1: print("Your lucky number is...") 2: lucky = 7 3: # Display the lucky number 4: print(lucky)
Line number 3
The following code snippet contains an error. What is the error? cost = int(input("Enter the cost: ")) if cost > 100 cost = cost - 10 print("Discounted cost:", cost)
Logical error: use of an uninitialized variable
What error will Python display when it attempts to execute the following if/else statement? if a == b : print("Equal") else : print("Not Equal") if a > b : print("a is larger") else : print("b is larger")
Python will display an error indicating that there is a problem with the indentation
Which parts of the computer store program code?
Secondary storage
The code snippet below is supposed to check whether an integer greater than 1 is a prime number. What will be the result of executing it? j = 2 result = 0 number = int(input("Please enter an integer (2 or greater):")) while j < number : if number % j == 0 : result = 1 j = j + 1 if result == 1 : print("Number:", number, "is Not Prime.") else : print("Number:", number, "is Prime.")
The code snippet displays the desired result.
Although the following code statement is valid, [print(10/0)], what will happen when this code is executed?
The error message ZeroDivisionError: int division or modulo by zero is displayed
To use or call a function, you need to specify:
The function name and it's arguments
Which statement is correct about the execution of the loop in the following code fragment? num = int(input("Please enter a number (0 when done): ")) incr = 0 while num != 0 : incr = incr + 1 num = int(input("Please enter a number (0 when done): ")) print(incr)
The program prints the count of inputs not equal to zero.
What is wrong with the following code snippet? print("Hello") print("World!")
The second line should not be indented
Which statement about if statements is not correct?
The statements in a statement block must be indented 2 spaces more than the header.
When hand-tracing the loop in the code snippet below, which variables are important to evaluate? i = 10 j = 5 k = -10 sum = 0 while i > 0 : sum = sum + i + j i = i - 1 print("Iteration: ", i)
The variables i and sum
When does the execution switch from the inner to the outer loop? j = 1 for i in range(0, 10) : while(j < 5) : print("Hello") if j == 2 : j = 6 j = j + 1 print("switch from inner to outer", i, " ", j)
When the value of j becomes 6
Consider the following code snippet: age = int(input("Enter your age: ")) if age < 13 : print("Child", end="") if age >= 13 and age <= 19 : print("Teen", end="") if age > 19 and age < 30 : print("Young adult", end="") if age >= 30 and age <= 50 : print("Adult", end="") if age > 50 : print("Young at heart", end="") Assuming that the user enters 55 as the age, what is the output?
Young at heart
A sequence of steps that is unambiguous, executable, and terminating is called:
an algorithm
How is a value stored in a variable?
an assignment statement
Which operators listed below are considered boolean operators:
and/or
Which of the following statements draws a circle?
canvas.drawOval(200, 100, 200, 200)
Computers are machines that:
execute programs
Which of the following for loops will run the loop body 5 times?
for i in range(0, 5) :
Consider the following code segment: for i in range(4) : ____________________ print("*", end="") print() It is supposed to generate the following output: *** *** *** *** Which line of code should be placed in the blank to achieve this goal?
for j in range(3) :
Consider the following for loop: for i in range(0, 10) : print(i) Which of the following while loops will generate the same output?
i = 0 while i < 10 : print(i) i = i + 1
What are the values of i and j after the following code snippet is run? i = 10 j = 20 count = 0 while count < 5 : i = i + i i = i + 1 j = j - 1 j = j - j count = count + 1 print("i = ", i , ", j = ", j)
i = 351, j = 0
What statement is used to implement a decision?
if
Which of the following checks to see if there is a comma anywhere in the string variable name?
if "," in name :
Which of the following if statements is problematic because of the limited precision of floating-point numbers?
if "10" == 5 :
Review the code snippet below: maritalStatus = input("Enter your marital status (s for single, m for married): ") maritalStatus = maritalStatus.upper() Which of the following statements can be used to validate whether the user entered a valid marital status?
if maritalStatus == "S" or maritalStatus == "M" :
Which of the following options checks that city is neither Atlanta or Philadelphia?
if not (city == "Atlanta" or city == "Philadelphia")
Consider the following code segment: s1 = "CAT" s2 = "cat" Which of the following if statements has a condition that evaluates to True?
if s1 < s2 :
Using De Morgan's law, what is the equivalent to this statement? if not (state == "PA" or state == "OH")
if state != "PA" and state != "OH"
Rewrite the following algebraic expression to an equivalent Python expression: 32 <= temp <= 100
if temp >= 32 and temp <= 100
Consider the following code segment. It is designed to identify the first location within a string, text where two adjacent characters are the same. i = 1 found = False while not found and i < len(text) : ____________________ : found = True else : i = i + 1 What line of code should be placed in the blank to achieve this goal?
if text[i] == text[i - 1] :
A computer program is a sequence of:
instructions and decisions
Which statement correctly creates a new variable by combining the two string variables: firstName and lastName?
name = firstName + lastName
What is the right way to assign the value of num + 10 to num2?
num2 = num + 10
The Central Processing Unit is primarily responsible for:
performing program control and data processing.
Which of the given print statements generates the following output? ABCDE"\
print("ABCDE\"\\")
Which statement computes the square root of 5 and stores it in the variable, r? Assume that the math module has already been imported.
r = math.sqrt(5)
Which of the following expressions will generate a random integer in the range -20 to 20, inclusive, where each value has an equal chance of being generated?
randint (-20, 20)
A messy network of possible pathways through a program is referred to as:
spaghetti code
Which code snippet is the correct Python equivalent to the following Algebraic expression ? c = √(a2 + b2)
sqrt(a ** 2 + b ** 2)
Water is liquid between 0 and 100 degrees Celsius. The following code segment should display a message if the water is not liquid. For this question, we will assume that water is liquid if it is exactly 0 degrees or exactly 100 degrees. if _________________ : print("The water is not liquid") What condition should be placed in the blank to achieve the desired behavior?
temp < 0 or temp > 100
Which of the following code segments is an example of a nested loop?
while i < 0 : while x == 10 :
The following program is supposed to continue reading values from the user until a value between 25 and 75 is entered. What line of code must be inserted in the blank so that the program will achieve this goal? value = int(input("Enter a value: ")) ____________________ value = int(input("Enter a value: "))
while value < 25 or value > 75 :
A graphics application shows information inside a
window
The line of code which reads a value from the user and stores it in a variable named x as a floating-point value is:
x = float(input("Enter the value of x: "))
Which line of code will generate a random integer from 1 up to and including 10, and store it in x? Assume that the randint function has been imported from the random module.
x = randint(1, 10)
Which line of code will generate a random floating-point number between 0 and 6, and store it in x? Assume that the random function has been imported from the random module.
x = random() * 6
The following while loop should continue to run as long as the user does not enter a negative number. What condition should be used to achieve this behavior? x = int(input("Enter an integer: ")) while ____________ : x = int(input("Enter an integer: "))
x >= 0
Assuming that the user provides 95 as input, what is the output of the following code snippet? y = int(input("Please enter a number: ")) if y > 300 : x = y else : x = 0 print("x:", x)
x: 0
Assuming that the user provides 303 as input, what is the output of the following code snippet? y = int(input("Please enter a number: ")) if y > 300 : x = y else : x = 0 print("x:", x)
x: 303