MIS 303 Chapter 3 MC - Test 2

Ace your homework & exams now with Quizwiz!

How many times will "Hi there!" be displayed after the following code executes? num = 2 while num < 12: print("Hi, there!") num += 2 Select one: a. 5 b. 6 c. 2 d. 12

a. 5

For the following code, what will the result be if the user enters 4 at the prompt? product = 1 end_value = int(input("Enter a number: ")) for i in range(1, end_value+1): product = product * i i += 1 print("The product is ", product) Select one: a. The product is 24 b. The product is 1 c. The product is 6 d. The product is 4

a. The product is 24

For the following code, what will the result be if the user enters 4 at the prompt? product = 1 end_value = int(input("Enter a number: ")) for i in range(1, end_value): product = product * i i += 1 print("The product is ", product) Select one: a. The product is 6 b. The product is 24 c. The product is 1 d. The product is 4

a. The product is 6

Which of the following in this expression is evaluated first?age >= 65 and status == "retired" or age < 18 Select one: a. age >= 65 b. status == "retired" c. status == "retired" or age < 18 d. age <= 18

a. age >= 65

To jump to the end of the current loop, you can use the Select one: a. break statement b. end statement c. continue statement d. switch statement

a. break statement

Which type of expression has a value of either true or false? Select one: a. binary b. Boolean c. relational d. if-else

Boolean

Given the following code, select the compound condition that makes sure that the input is an integer greater than 0 and less than 1,000.my_num = input("Enter a number between 1 and 999:")check_num = int(my_num)while _________________________:my_num = input("Try again. The number must be between 1 and 999") check_num = int(my_num) Select one: a. check_num <= 0 or check_num >= 1000 b. check_num < 0 and > 1000 c. check_num <= 0 or check_num > 1000 d. check_num <= 0 and check_num != 1000

a. check_num <= 0 or check_num >= 1000 d. check_num <= 0 and check_num != 1000

Which of the following creates a Boolean variable? Select one: a. flag = True b. flag = True or False c. flag == "False" d. if flag == True:

a. flag = True

To compare two strings with mixed uppercase and lowercase letters, a programmer can first use the Select one: a. lower() method to convert all characters in each string to lowercase. b. lower() method to convert all characters after the first character in each string to lowercase. c. upper() method to convert all characters after the first character in each string to uppercase. d. upper() method to convert the first character in each string to uppercase.

a. lower() method to convert all characters in each string to lowercase.

What will the output of the following code be if the user enters 3 at the prompt?your_num = int(input("Enter a number:"))while (your_num > 0):product = your_num * 5print(your_num, " * 5 = ", product) your_num -= 1 Select one: a. 3 * 5 = 15 2 * 5 = 10 1 * 5 = 5 0 * 5 = 0 b. 3 * 5 = 15 2 * 5 = 10 1 * 5 = 5 c. 3 * 5 = 15 3 * 5 = 15 3 * 5 = 15 d. 3 * 5 = 15

b. 3 * 5 = 152 * 5 = 101 * 5 = 5

Which of the following is true for an if statement that has both elif and else clauses? Select one: a. The statements in the else clause are always executed. b. If the condition in the if clause is true, the statements in that clause are executed. c. If the condition in the else clause is true, the statements in that clause are executed. d. If the condition in an elif clause is true, the statements in that clause are executed.

b. If the condition in the if clause is true, the statements in that clause are executed.

Which of the following can use the range() function to loop through a block of statements? Select one: a. a break statement b. a for statement c. a while statement d. an if statement

b. a for statement

If you want to code an if clause, but you don't want to perform any action, you can code Select one: a. a skip statement b. a pass statement c. a break statement d. an end statement

b. a pass statement

In a while loop, the Boolean expression is tested Select one: a. until it equals the current loop value b. before the loop is executed c. after the loop is executed d. both before and after the loop is executed

b. before the loop is executed

Which of the following is not an acceptable way to code a nested structure? Select one: a. nest a while loop inside an elif clause b. nest an else clause within an elif clause c. nest an if statement inside a for loop d. nest a for loop inside a while loop

b. nest an else clause within an elif clause

When two strings are compared, they are evaluated based on the ___________________ of the characters in the string. Select one: a. alphabetical order b. sort sequence c. uppercase/lowercase sequence d. string method

b. sort sequence

What will be displayed after the following code is executed?counter = 1while counter <= 20:print(counter, end=" ")counter *= 3print("\nThe loop has ended.") Select one: a. 1 3 9 12 15 18 The loop has ended. b. 1 3 9 The loop has ended. c. 1 3 9 The loop has ended. d. 1 3 9 The loop has ended.

c. 1 3 9 The loop has ended.

num_widgets = 0while True:choice = input("Would you like to buy a widget? (y/n): ")if choice.lower() == "y":num_widgets += 1else:breakprint("You bought", num_widgets , "widget(s).") Refer to Code Example 3-1. Which of the following could be a pseudocode plan for the program? Select one: a. Define widget count variable IF user buys widgets add 1 to widget count ELSE end loop Display results b. Get user input Loop while input != "y" IF user buys widget add 1 to widget coun ELSE end loop Display results c. Define widget count variable Begin infinite loop Get user input IF user buys widget add 1 to widget count ELSEend loop Display results d. Get user input Loop WHILE user wants to continue IF user buys widget add 1 to widget count Get user input Display results

c. Define widget count variable Begin infinite loop Get user input IF user buys widget add 1 to widget count ELSE end loop Display results

num_widgets = 0while True:choice = input("Would you like to buy a widget? (y/n): ")if choice.lower() == "y":num_widgets += 1else:breakprint("You bought", num_widgets , "widget(s).") Refer to Code Example 3-1. If the user enters "no" at the prompt, what does the program print to the console? Select one: a. You bought 1 widget(s) today. b. Nothing, the break statement will cause the program to end c. You bought 0 widget(s) today. d. You bought no widget(s) today.

c. You bought 0 widget(s) today.

What will be displayed after the following code executes? guess = 19 if guess < 19: print("Too low") elif guess > 19: print("Too high") Select one: a. Too high b. Too low c. nothing will display

c. nothing will display

For the following code, what will the result be if the user enters 5 at the prompt?sum = 0end_value = int(input("Enter a number: "))for i in range(1, end_value):sum = sum + i print(sum, end=", ") Select one: a. 1, 3, 6, 10, 16, b. 1, 2, 3, 4, 5, c. 10, d. 1, 3, 6, 10,

d. 1, 3, 6, 10,

What will this loop display?sum = 0for i in range(0, 25, 5):sum += iprint(sum) Select one: a. 0, 5, 10, 15, 20, 25 b. 0, 5, 10, 15, 20 c. 30 d. 50

d. 50

How many times will "Hi again!" be displayed after the following code executes? for i in range(0, 12, 2): print("Hi, again!") Select one: a. 5 b. 2 c. 12 d. 6

d. 6

Which of the following begins by testing a condition defined by a Boolean expression and then executes a block of statements if the condition is true? Select one: a. a for statement b. a continue statement c. a switch statement d. a while statement

d. a while statement

The and operator has Select one: a. lower precedence than the or and not operators b. higher precedence than the or and not operators c. lower precedence than the or operator, but higher precedence than the not operator d. higher precedence than the or operator, but lower precedence than the not operator

d. higher precedence than the or operator, but lower precedence than the not operator

A for loop that uses a range() function is executed Select one: a. while the for condition is less than the value returned by the range() function b. until the range() function returns a false value c. until the for condition is equal to the value returned by the range() function d. once for each integer in the collection returned by the range() function

d. once for each integer in the collection returned by the range() function

Pseudocode can be used to plan Select one: a. the modules used in a program b. the conditions for control statements c. the functions used by a program d. the coding of control structures

d. the coding of control structures


Related study sets

NURS 3311 RN Mental Health Theories & Therapy Assessment

View Set

chapter 19: introduction to the respiratory system Med surg(106)

View Set

Georgia Rules and Codes Pertinent to Life and Accident & Sickness Insurance Only

View Set

Chapter 48: Diabetes MellitusThe nurse is assessing a 55-yr-old female patient with type 2 diabetes who has a body mass index (BMI) of 31 kg/m2 .Which goal in the plan of care is most important for this patient? a. The patient will reach a glycosylated he

View Set