WorksheetsPython Fundamentals
Total questions: 12
Worksheet time: 6mins
Analyze the following code.
count = 0
while count < 100:
# Point A
print("Welcome to Python!")
count += 1
# Point B
# Point C
count < 100 is always True at Point A
count < 100 is always True at Point B
count < 100 is always False at Point B
count < 100 is always True at Point C
How many times will the following code print "Welcome to Python"?
count = 0
while count < 10:
print("Welcome to Python")
9
10
11
infinite number of times
What will be displayed when the following code is executed?
number = 6
while number > 0:
number -= 3
print(number, end = ' ')
6 3 0
6 3
3 0
3 0 -3
The function range(5) return a sequence ______________.
1, 2, 3, 4, 5
0, 1, 2, 3, 4, 5
1, 2, 3, 4
0, 1, 2, 3, 4
A Python line comment begins with ________.
//
/*
#
$$
To start Python from the command prompt, use the command _______
execute python
run python
python
go python
What will be displayed by the following code?
print("A", end = ' ')
print("B", end = ' ')
print("C", end = ' ')
print("D", end = ' ')
ABCD
A, B, C, D
A B C D
A, B, C, D will be displayed on four lines
Suppose s = "Welcome", what is type(s)?
str
int
float
String
Given a string s = "Welcome", which of the following code is incorrect?
hint: a str object is immutable!
print(s[0])
s[1] = 'r'
print(s.strip())
print(s.lower())
What is the output of the following code?
x = 0
while x < 4:
x = x + 1
print("x is", x)
x is 1
x is 2
x is 3
x is 4
Analyze the following statement:
sum = 0
for d in range(0, 10, 0.1):
sum += sum + d
The program has a syntax error because the range function cannot have three arguments.
The program has a syntax error because the arguments in the range must be integers
The program runs in an infinite loop
The program runs fine
Which of the following loops prints "Welcome to Python" 10 times?
A:
for count in range(1, 10):
print("Welcome to Python")
B:
for count in range(0, 10):
print("Welcome to Python")
C:
for count in range(1, 11):
print("Welcome to Python")
D:
for count in range(1, 12):
print("Welcome to Python")
BD
ABC
AC
BC
