NEW
Font size
WorksheetsPython Basics - recap
Total questions: 18
Worksheet time: 9mins
Which of the following is a valid way to assign the value 10 to a variable called `distance` in Python?
`distance == 10`
`distance = 10`
`10 = distance`
`distance := 10`
What is the data type of the value `3.14` in Python?
Integer
String
Float
Boolean
Which of the following is the correct way to check if a variable `temperature` is greater than 20 in Python?
`if temperature > 20:`
`if temperature => 20:`
`if temperature >> 20:`
`if temperature = 20:`
What will be the output of the following code? ```python x = 5 if x < 10: print("Small") else: print("Large") ```
Small
Large
5
Error
Which of the following is a string in Python?
`42`
`"42"`
`42.0`
`True`
What is the result of the following code? ```python count = 0 while count < 3: count = count + 1 print(count) ```
0
1
2
3
Which of the following is the correct way to start a `for` loop that repeats 5 times in Python?
`for i in 1 to 5:`
`for i in range(5):`
`for i = 1; i <= 5; i++:`
`for (i in 5):`
What will be printed by the following code? ```python for i in range(2, 5): print(i) ```
2 3 4
2 3 4 5
3 4 5
2 3 4 5 6
Which of the following is a Boolean value in Python?
`yes`
`True`
`"False"`
`1.0`
What is the value of `result` after this code runs? ```python result = 7 if result == 7: result = result + 3 ```
7
3
10
0
Which of the following statements will create a variable called `weight` and assign it the value 12 kilograms?
`weight = 12`
`weight == 12`
`weight := 12`
`12 = weight`
What is the output of the following code? ```python x = 8 if x % 2 == 0: print("Even") else: print("Odd") ```
Even
Odd
8
Error
Which of the following is NOT a valid Python data type?
Integer
String
Character
Boolean
How many times will the following loop run? ```python for i in range(4): print(i) ```
3
4
5
0
What is the value of `total` after this code runs? ```python total = 0 for i in range(1, 4): total = total + i ```
3
4
6
7
Which of the following is the correct way to check if a variable score is equal to 100 in Python?
if score != 100:
if score === 100:
if score = 100:
if score == 100:
What will be the output of the following code?value = 9
if value > 10:
print("High")
else:
print("Low")
9
Error
Low
High
How many times will the following loop execute?for i in range(2):
print(i)
1
2
3
0
