Font size
WorksheetsPython Unit 02 - Libraries and Variables
Total questions: 31
Worksheet time: 16mins
You've been asked to write a program that asks a user for a value. The value must be used as a whole number in a calculation even if the user enters a decimal value. To help complete the code for this requirement, which code segment should you use?
total_items = float(input("How many items would you like?"))
total_items = input("How many items would you like?")
total_items = str(input("How many items would you like?"))
total_items = int(input("How many items would you like?"))
Match the data type to the code segment containing it.
Which of the segment below would represent a type bool
age = 2
tiger = False
name = "Albert"
grade = 91.7
zip = "32054"
Match the data type to the code segment containing it.
Which of the segment below would represent a type int
age = 2
tiger = False
name = "Albert"
grade = 91.7
zip = "32054"
Match the data type to the code segment containing it.
Which of the segment below would represent a type str
age = 2
tiger = False
name = "Albert"
grade = 91.7
Match the data type to the code segment containing it.
Which of the segment below would represent a type float
age = 2
tiger = False
name = "Albert"
grade = 91.7
zip = "32054"
After running code segment 1 shown below, what will the data type of variable a be?
# Code segment 1
x1 = "20"
y1 = 3
a = x1 * y1
str
int
float
bool
none of these, code will produce an error instead.
After running code segment 2 shown below, what will the data type of variable b be?
# Code segment 2
x2 = 6
y2 = 4
b = x2 / y2
str
int
float
bool
none of these, code will produce an error instead.
After running code segment 3 shown below, what will the data type of variable c be?
# Code segment 3
x3 = 2.5
y3 = 1
c = x3 / y3
str
int
float
bool
none of these, code will produce an error instead.
Evaluate the following Python arithmetic expression and identify the correct result.
(3*(1+2)**2 - (2**2)*3)
3
13
15
69
You are writing code that generates a random integer with a minimum value of 5 and a maximum value of 11. Which TWO functions should you use. Each correct answer presents a complete solution. (CHOOSE TWO)
random.randint(5, 11)
random.randint(5, 12)
random.randrange(5, 12, 1)
random.randrange(5, 11, 1)
You need to accept input from the user and print that information to the user screen.
01 print("What is your name?")
02
03 print(name)
You have started the following code, but haven't finished it yet. What should go on line 02?
name = input
input("name")
input(name)
name = input()
You develop a Python application for your company. You want to add notes to your code so that other team members will understand it.
What should you do?
Place the notes after the # sign on any line.
Place the notes after the last line of code separated by a blank line.
Place the notes before the last line of code separated by a blank line.
Place the notes inside of the parentheses on any line.
Identify the correct data type to the type operation shown below:
type(+1E10)
int
float
str
bool
Identify the correct data type to the type operation shown below:
type(5.0)
int
float
str
bool
Identify the correct data type to the type operation shown below:
type("True")
int
float
str
bool
Identify the correct data type to the type operation shown below:
type(False)
int
float
str
bool
You have written the following line of code in your Python program:
value = a+b*c-d
Which part of the expression will be evaluated FIRST?
a+b
b*c
c-d
You have written the following line of code in your Python program:
value = a+b*c-d
Which part of the expression will be evaluated SECOND?
addition
subtraction
multiplication
You have written the following line of code in your Python program:
value = a+b*c-d
Which expression below is equivalent to this expression?
(a+b)*(c-d)
(a+(b*c))-d
a+((b*c)-d)
What will the output be from the following Python code?
print(9/3)
3
3.0
9/3
SyntaxError
What is the Python built-in function to converts a number to a string?
str()
int()
parseInt()
convert
Two symbols are missing from the codes (see picture).
Choose the correct symbols to ensure the input function works.
1st blank: "
2nd blank: "
1st blank: #
2nd blank: #
1st blank: !
2nd blank: !
1st blank: (
2nd blank: )
Two symbols are missing from the codes (see picture).
Choose the correct symbols to ensure the concatenation works.
1st blank: +
2nd blank: +
1st blank: "
2nd blank: "
1st blank: (
2nd blank: )
1st blank: #
2nd blank: #
x = 5
y = 6
print("x*y")
The code above displays the following:
11
x*y
Syntax Error
30
In python the ' FLOAT data type' can be defined as...?
holds alphanumerical data
holds whole numbers
holds a number with a decimal part
hold either true or false
In Python the ' BOOLEAN data type' can be defined as...?
holds alphanumerical data
holds whole numbers
holds a number with a decimal point
holds either true or false
If we needed to store information such as a ZIP CODE in PYTHON, what data type would we use?
String (alphanumerical)
Float (decimal point)
Boolean (true or false)
What is keeping the following math code from successfully executing?
number_one = input("Enter a number: ")
number_two = input("Enter a second number: ")
print(number_one + number_two)
Because variables cannot be longer than 1 word
Because number_one and number_two are strings
Because input is an invalid function
Python will always think that it has to add 1+2
Program works as is.
What will the code below print if -
num1 = 5 and num2 = 8?
num1 = input("Number 1")
num2 = input("Number 2")
print(num1+num2)
85
58
5+8
None of the above
13
