stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
python loops Flashcards | StudBud
Explore
/
python loops
python loops
20 terms
·
StudBud Administration
·
49 plays
Imported from external platform
Flashcards
20 cards
F
Practice quiz
P
Host live
L
Questions
20
Answers
1
How is a code block indicated in Python?
indentation
brackets
key
none of the above
2
What will be the output of the following code snippet? x = 10 || if x > 5: || print("x is greater than 5")
c) x is equal to 5
a) x is greater than 5
b) x is less than 5
d) No output
3
Which of the following types of loops are not supported in Python?
for
none of the above
do-while
while
4
Which keyword is used to execute a block of code if the condition in the if statement is false?
elif
for
else
while
5
How can you execute multiple statements under a single if block in Python?
c) Use the and keyword between statements
b) Indent the statements to the same level
a) Separate statements with a semicolon
d) Use the elif keyword
6
What is the purpose of the for loop in Python?
d) To define a function
a) To execute a block of code repeatedly until a condition is false
c) To execute a block of code a fixed number of times
b) To iterate over items in a sequence
7
What is the purpose of the elif statement in Python?
To define a loop
To execute a block of code if the previous conditions are false
To perform arithmetic operations
To exit from a loop
8
What is the syntax for a for loop in Python?
d) All of the above
c) for index in range(len(sequence)):
a) for item in sequence:
b) for item in range(n):
9
Which function is used to read input from the console in Python?
input()
getinput()
scan()
read()
10
What is the syntax for a while loop in Python?
d) while loop condition:
c) while (condition):
a) while condition:
b) while condition():
11
What data type would you use to store a whole number in Python?
string
int
bool
float
12
Which function in Python is used to display data as output?
show()
print()
output()
display ()
13
What is the purpose of the while loop in Python?
b) To execute a block of code a fixed number of times
c) To define a function
d) To iterate over items in a sequence
a) To execute a block of code repeatedly until a condition is false
14
What is the primary purpose of the if statement in Python?
a) To execute a block of code based on a condition
b) To perform mathematical operations
c) To repeat a block of code
d) To define a function
15
What is the purpose of the range() function in Python?
a) To generate a sequence of numbers
c) To define a function
d) To execute a block of code repeatedly until a condition is false
b) To iterate over items in a sequence
16
What will the following code snippet print? for i in range(3): || print(i)
a) 0 1 2
d) 3 2 1 0
c) 2 1 0
b) 1 2 3
17
print(type("Hello, World!"))
complex
str
float
int
18
fruits = ["apple", "banana", "cherry"] || for fruit in fruits: print(fruit)
a) apple banana cherry
b) [“apple”, “banana”, “cherry”]
d) No output
c) 0 1 2
19
Which of the following is not a Python built-in data type?
dict
array
frozenset
set
20
What will be the data type of the variable x after this assignment: x = 3.5?
str
float
complex
int