LIS4369 (Python) Q1
once for each integer in the collection returned by the range() function
A for loop that uses a range() function is executed
You bought 0 widget(s) today.
Consider the following code: num_widgets = 0 while True: choice = input("Would you like to buy a widget? (y/n): ") if choice.lower() == "y": num_widgets += 1 else: break print("You bought", num_widgets , "widget(s).") If the user enters "Y" at the prompt, what does the program print to the console?
You bought 0 widget(s) today.
Consider the following code: num_widgets = 0 while True: choice = input("Would you like to buy a widget? (y/n): ") if choice.lower() == "y": num_widgets += 1 else: break print("You bought", num_widgets , "widget(s).") If the user enters "no" at the prompt, what does the program print to the console?
The product is 6
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)
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+1): product = product * i i += 1 print("The product is ", product)
1, 3, 6, 10,
For the following code, what will the result be if the user enters 5 at the prompt? sum = 0 end_value = int(input("Enter a number: ")) for i in range(1, end_value): sum = sum + i print(sum, end=", ")
check_num <= 0 or check_num > 1000
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)
6
How many times will "Hi again!" be displayed after the following code executes? for i in range(0, 12, 2): print("Hi, again!")
5
How many times will "Hi there!" be displayed after the following code executes? num = 2 while num < 12: print("Hi, there!") num += 2
a pass statement
If you want to code an if clause, but you don't want to perform any action, you can code
before the loop is executed
In a while loop, the Boolean expression is tested
the coding of control structures
Pseudocode can be used to plan
10Peaches, 1peach, Peach, peach
Python will sort the strings that follow in this sequence: Peach peach 1peach 10Peaches
higher precedence than the or operator, but lower precedence than the not operator
The and operator has
multitasking
UNIX and Linux are ____ systems, which allow one user to execute more than one program at a time
multiuser
UNIX/Linux are ____ systems, which let many people simultaneously access and share the resources of a server computer.
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 = 0 while True: choice = input("Would you like to buy a widget? (y/n): ") if choice.lower() == "y": num_widgets += 1 else: break print("You bought", num_widgets , "widget(s).") Which of the following could be a pseudocode plan for the program?