Font size
WorksheetsPython variables and operators quiz
Total questions: 20
Worksheet time: 9mins
Which of the following is NOT a valid Python data type?
float
int
str
positive
To test whether one number is greater than or equal to another, you would use the (a) conditional operator.
Which of the following is a valid Python assignment statement?
x = 3
x := 3
x == 3
x <- 3
What is the correct Python syntax to output the type of a variable?
print(type(x))
print(typeof(x))
print(typeof x)
print(type x)
How do you insert COMMENTS in Python code?
// this is a comment
/* this is a comment */
# this is a comment
-- this is a comment
Which of the following is NOT a Python keyword?
for
while
loop
if
Which of the following will prompt a user for input and assign that input to a variable?
x = input("Please enter your name: ")
x = get(input)
x = prompt("Enter your name: ")
x = "Please enter your name: "
How do you declare a variable in Python?
var x = 10;
int x = 10;
x = 10
declare x = 10;
What is the output of the following Python code snippet?
print(type(5.0))
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
Which of the following is NOT a valid Python comparison operator?
!=
==
<=
=<
What symbol is used at the end of an if, else, or elif statement to indicate the code that follows is part of a separate block of code that is only executed if the condition is met?
:
|
@
#
You should (a) input to another data type if you don't want a string.
Given the code x = 3 + 5.0, the value of x is (a)
Given the code x = 3 + 5.0, what does print(type(x)) show?
<class 'float'>
<class 'int'>
<class 'str'>
<class 'bool'>
Given the code
biff = ['foo', 'bar', 'bam']
print(type(biff))
what is the result?
<class 'list'>
<class 'str'>
<class 'foo, bar, bam'>
foo, bar, bam
If I wanted to create a series of related values, I would use the (a) data type.
If I want to print formatted output in Python, I should use which built-in function?
Match the following
The code prints a string
print("Hello World")
The code concatenates (adds) strings together and prints the result
print("Hello" + " " + "World")
The code prints a formatted string with the value of an integer variable
print("I have {:d} cats".format(3))
What is the output of the following Python code?
x = 5
y = 10
print(x + y)
15
510
5 + 10
None of the above
What is the output of the following Python code snippet? print(5 // 2)
2.5
2
3
None of the above
