cs practice 2 quiz

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is printed by the following code snippet if itemCount contains a value of 10 and cost contains 80: if itemCount > 5 : discount = 0.8 totalcost = cost * discount print("Total discounted price is:", totalCost) -Nothing, the program will run but not print any results -Total discounted price is: 64 -Total discounted price is: 16 -Total discounted price is: 0

-Total discounted price is: 64

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? 3 4 1 2

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? 4 1 5 2

1

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) -95 -105 -100 -110

110

What is the output of the following code snippet? x = 20 if x <= 20 : print("1", end="") if x <=40 : print("2", end="") if x <= 30 : print("3", end="") -1 -123 -3 -2

123

Assuming a user enters 30, 20, and 10 as the input values, 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 : if num1 > num3 : print(num1) else : print(num3) else : if num2 > num3 : print(num2) else : print(num3) -20 -10 -0 -30

30

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) 34 33 35 36

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: 5 4 -1 0

4

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) 105 49 45 43

49

What is the value of the price variable after the following code snippet is executed? price = 42 if price < 40 : price = price + 10 if price > 30 : price = price * 2 if price < 100 : price = price - 20 42 84 52 64

64

What are the two parts of an if statement? -An increment and a return value -A boolean and an operator -A condition and a body

A condition and a body

Copy of What is the output of the following code snippet if count contains 56? if count % 2 == 0 : print("Count is an even number") else : print("Count is an odd number") -Nothing, the program runs but does not print any output -Count is an odd number -Count is an even number -Nothing, there is a syntax error

Nothing, there is a syntax error ************

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") -No error will be displayed -Python will display an error indicating that == should be replaced with = -Python will display an error indicating that an if statement cannot reside inside the body of an else -Python will display an error indicating that there is a problem with the indentation

Python will display an error indicating that there is a problem with the indentation

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 -Python will display an error indicating that = should be replaced with == -No error will be displayed -Python will display an error indicating that an if statement cannot reside inside the body of an else

Python will display an error indicating that there is a problem with the indentation *********

The following code snippet contains an error. What is the error? if cost > 100 cost = cost - 10 print("Discounted cost:", cost) Syntax error: incorrect indentation Logical error: use of an uninitialized variable Syntax error: missing an else statement Syntax error: missing colon after if statement

Syntax error: missing colon after if statement

Which of the following statements is true about the if statement? -The if and else blocks can be aligned to any indentation level. -The else block is optional. -The if statement can have only one condition that evaluates to an integer value. -The if block is optional.

The else block is optional.

Which of the following correctly identifies what is wrong with the code snippet below: if y > 300 : x = y else : x = 0 print("x:", x) -The statement after the if statement and the statement after the else statement must be indented -Nothing, the program runs as intended -No colon is needed after the else statement -The statement after the if statement must be indented

The statement after the if statement and the statement after the else statement must be indented

Consider the following code segment. It is designed to classify widgets as too small if they are less than 10mm in diameter or too large if they are 15mm in diameter or more. Otherwise they should be classified as just right. However, this code may contain a bug. Examine the program, and identify what bug, if any, is present. if size >= 0 : print("Too small") elif size >= 10 : print("Just right") elif size >= 15 : print("Too big") -The greater than or equal signs need to be replaced with greater than signs -The order of the conditions (and bodies) must be changed -There is nothing wrong with the code segment (it works as intended) -All instances of elif need to be replaced with else

There is nothing wrong with the code segment (it works as intended) *******************

Consider the following code segment: if a == b : print("W") else : print("X") if b == c : print("Y") else : print("Z") If a, b and c are all 0 then the output generated by this code segment is: -W -W followed by X on the next line, followed by Y on the next line -W followed by Y on the next line -X followed by Y on the next line

W followed by X on the next line, followed by Y on the next line *********

What is the definition of a nested statement? -Allows a program to carry out different actions depending on the nature of the data to be processed -When a decision statement is contained inside the branch of another decision statement -A compound statement that consists of a header and a statement block -A statement that is used to validate user input

When a decision statement is contained inside the branch of another decision statement fixed idk***********

Consider the following code segment: if a > b : print("X") if a == b : print("Y") What is displayed if a is 1 and b is 0? -X -Nothing -Y -X followed by Y on the next line

X *****************

Consider the following code segment: if a == b : print("W") else : print("X") if b == c : print("Y") else : print("Z") If a is 0, b is 1 and c is 1 then the output generated by this code segment is: -X -W -X followed by Z on the next line -X followed by Y on the next line

X followed by Y on the next line

Consider the following code segment: if a == b : print("W") else : print("X") if b == c : print("Y") else : print("Z") If a is 0, b is 1 and c is 0 then the output generated by this code segment is: X followed by Z on the next line X followed by Y on the next line W X

X followed by Y on the next line *****************

Consider the following code segment: if a > b : print("X") if a == b : print("Y") What is displayed if a is 0 and b is 0? X Y X followed by Y on the next line Nothing

Y ***********

What is the output of the following code snippet if the cost contains 100: if cost > 150 : discount = 0.8 * cost else : discount = cost print("Your cost is:", discount) -Your cost is: 100 -Nothing, the code contains a syntax error -Your cost is: 80 -Your cost is: 0

Your cost is: 100

What is the opposite of this condition? count > 10? -count <= 10 -count <= 9 -count < 9 -count >= 10

count <= 10

A store provides a 10% discount on all items with a price of at least $100. Otherwise, no discount is applicable. Which of the following DOES NOT correctly compute the discount? -discount = 0 if price !< 100 : discount = 0.10 * price -discount = 10 if price >= 100 : discount = 0.1 * price else : discount = 0 -discount = 0 if price >= 100 : discount = 0.10 * price -discount = 0.10 * price if price <= 100 : discount = 0

discount = 0.10 * price if price <= 100 : discount = 0

The operator >= stands for not equal to greater than or equal to this is not a valid Python operator greater than

greater than or equal to

What statement is used to implement a decision? import while for if

if

Which of the following code segments is an example of a nested if statement? -if a == b : print(a) else: print(b) -if a == b : print(a) -if a == b : print(a) if c == d : print(c) -a = a - 1 if a > 0 else a = a + 1

if a == b : print(a) if c == d : print(c)

Which condition will cause the body of the if statement to execute when count is 0? -if count == 0 -if count =< 0 -if count = 0 -if count < 0

if count == 0

Consider the following code snippet: number = int(input("Enter a number: ")) if number > 30 : ... elif number > 20 : ... elif number > 10 : ... else : ... Assuming that the user input is 40, which block of statements is executed? if number > 30 : ... else : ... else if number > 10 : ... else if number > 20 : ...

if number > 30 : ...

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 : if s1 >= s2 : if s1 == s2 : if s1 = s2 :

if s1 < s2 :

Which statement correctly tests if the user entered the letter Y? if userInput == "Y" : if userInput = "y" : if userInput == "y" : if userInput = "Y" :

if userInput == "Y" :

Which of the following is the correct syntax for an if statement? -if (x < 10) size = "small" else (x < 20) size = "medium" -if (x < 10) size = "small"; -if x < 10 : size = "small" else size = "medium" -if x < 10 : size = "small" else : size = "medium"

if x < 10 : size = "small" else : size = "medium"

Consider the following code snippet: age = int(input("Enter your age: ")) if age < 10 : print("Child") if age < 30 : print("Young Adult") if age < 70 : print("Old") if age < 100 : print("Impressively old") Assuming that the user inputs 80 as the age, what is the output? Impressively old Young adult Old Child Young adult Old Child Young adult Old Impressively old

impressively old

Which of the following conditions is true, given that num1 contains 3 and num2 contains 4? num1 + num2 != 7 num1 - num2 <= 0 num1 + 1 > b num1 + 1 < b

num1 - num2 <= 0

Consider the following code snippet: num1, num2, num3, num4, num5 = 0, 0, 0, 0, 0 num1 = int(input("Enter a number: ")) num2 = int(input("Enter a number: ")) if num1 < num2 : num3 = num1 else : num3 = num2 if num1 < num2 + 10 : num4 = num1 elif num1 < num2 + 20 : num5 = num1 print("num1 =", num1, "num2 =", num2, "num3 =", num3, "num4 =", num4, "num5 =", num5) Assuming that the user enters the numbers 20 and 12 as the two input values, what is the output of the code snippet? num1 = 20 num2 = 12 num3 = 20 num4 = 20 num5 = 0 num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0 num1 = 20 num2 = 12 num3 = 12 num4 = 0 num5 = 20 num1 = 20 num2 = 12 num3 = 20 num4 = 0 num5 = 20

num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0

Assuming the user enters 15 as input, what is the output of the following code snippet number = int(input("Please enter a number: ")) if number >= 20 : print("The numer is big") else : print("The number is small") -The number is small -There is no output due to a syntax error -The number is big -The program runs successfully but does not print any output

the number is small

Which of the following options refers to the technique of simulating program execution on a sheet of paper? -Prototyping -Debugging -Tracing -Compiling

tracing

Which of the following values make the expression not x == b and c > x true? x = 10, b = 20, c = 15 x = 10, b = 2, c = 5 x = 10, b = 10, c = 15 x = 10, b = 20, c = 10

x = 10, b = 20, c = 15

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: 303 -x: 300 -x: 0 -There is no output due to a syntax error

x: 300 *************

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) There is no output due to a syntax error. x: 300 x: 303 x: 0

x:303

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? -Intermediate -High -Too high -Too small

High

What is the output of the following code snippet if count contains 56? if count % 2 == 0 : print("Count is an even number") else : print("Count is an odd number") Nothing, the program runs but does not print any output Count is an odd number Nothing, there is a syntax error Count is an even number

Count is an odd number **************

What is the error in this statement? if count = max : print("You win") -Equality is evaluated using two equal signs (==), not one. -The print function should not be indented -There must be an else statement

Equality is evaluated using two equal signs (==), not one.


Conjuntos de estudio relacionados

Chapter 4 Accounting, Chapter 5 Quiz, Chapter 6 Accounting, Chapter 7 Quiz

View Set

Module Sept. COLLISIONS: COSTS AND PREVENTIONS

View Set

Thermochemistry Practice Test 2020

View Set

Peds Exam 2 Q's: Hematologic & Genetic

View Set