NEW
Font size
WorksheetsUnit 3: Basic Python & Console Interaction
Total questions: 21
Worksheet time: 11mins
What is the final result of the expression 10 + 4 * 5
What is the final result of the expression 8 / 3 + 6
Choose the print statement below that will cause an error. Assume that num has the value 6, and name has the value George.
print(name + ":" )
print(num)
print(name + " wants " + "num " + "candies")
print(name + ": " + str(num))
print(name + ": " + num)
Which one of the statements below will cause an error?
y = "yes" * 6
y = "yes" + 10
y = "yes" + "yes"
y = ("a"*4)+"b"
What does the following program print?
<class 'str'>
<class 'int'>
<class 'float'>
The program crashes & doesn't print anything.
Suppose you have a variable defined num = "4". What is the variable type of num?
int
float
str
number
Choose the option that correctly prints out the variable(s).
What kind of data does a float variable contain?
Whole numbers
Words
Numbers that can have decimal components
A float is not a Python variable type
What kind of data does an int variable contain?
Whole numbers
Words
Numbers that can have decimal components
A float is not a Python variable type
What does the following code print?
6.8
8.8
6
8.8
6
8
The code causes an error
Which of the following options is the best way to get a number from the user that you plan to use in a mathematical equation?
num = str(input(“Enter a number: “))
num = number(input(“Enter a number: “))
num = input(“Enter a number: “)
num = int(input(“Enter a number: “))
What is the final result of the expression 2**5?
2
25
32
That is not a valid Python expression
What is the character that in (single) -line Python comments begin with?
#
%
*
"
What is the difference between a binary operator and a unary operator?
A computer can use binary operators, but it cannot use unary operators.
A unary operator needs two things, while a binary operator only needs one.
A binary operator needs two things, while a unary operator only needs one.
Binary operators are used for arithmetic expressions, while unary operators are for strings.
On which line of code will Python error?
Line 1
Line 2
Line 3
Line 4
In what order should these statements be executed in order to get input from the user and print out the result?
A) response = input("Do you like cheese? ")
B) print("You have chosen " + confirm)
C) print("You responded " + response)
D) confirm = input("Are you sure? ")
A, B, C, D
B, C, A, D
A, C, D, B
C, B, A, D
What is the output of the following program? Assume the user enters “Gordon”, then “Sumner”.
Sumner Gordon
Gordon
Sumner
GordonSumner
Gordon Sumner
Which of the following statements is true about print statements?
I. In order to print a string literal, the string must be enclosed in quotes.
II. Each print statement will be printed on its own line.
III. Print statements will not let you print string and number characters in the same statement.
IV. Print statements are how you display text on the screen.
I, IV
II, III
I, II, IV
I, III, IV
Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?
first_name
f1r5tn4m3
first!name!
1name
Which of the following choices is NOT a Python variable type?
float
str
bool
num
Choose the correct declaration of a float variable with the value 2.71828.
Euler = "2.71828"
Euler = int(2.71828)
Euler = 2.71828
float Euler = 2.71828
