Font size
WorksheetsPython - Unit 1 and 2 REVIEW
Total questions: 55
Worksheet time: 32mins
print ("Hello" , "world")
What will the output be from the following code?
print(3+4)
3+4
7
SyntaxError
print(3+4)
What would this print?
What will the output be from the following Python code?
print(Hello world!)
Hello world!
SyntaxError
Hello world
print(Hello world!)
What is the Python built-in function to converts a number to a string?
str()
int()
parseInt()
convert
The correct syntax for converting the string x to uppercase is :
X.upper()
upper(x)
x.UPPER[ ]
x.upper()
The correct syntax for converting the string myname to lowercase is :
myNAME.lower[ ]
myname.lower( )
myname.upper( )
myname_lower(12 )
Let x= "Python", the output of print(x.upper()) is
python
PYTHON
_PYTHON
"PYTHON"
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
What is a piece of code that can take inputs to perform a certain task?
a function
arguments
parameters
Consider the line of code:
Football('Go Wildcats', 14, 21)
What is the Football?
argument
parameter
function name
Consider the line of code:
Football('Go Wildcats', 21, 14)
What is 'Go Wildcats' ?
argument
parameter
function name
When defining a function, the definition must occur before it is called.
true
false
Which of the following terms best describes the code above?
function call
function definition
What is the name for the code highlighted in red?
function name
function definition
parameters
arguments
Line 6 is called
function definition
function call
function name
What is a parameter in a function?
input value to a function for the function’s execution
a variable used to send information to a function
the name of the function
the name of the main program calling the function
Choose the correct output of calling the function below with the call statement below:
def lowCase(words):
return words.lower()
myWords= lowCase("No CAPITAL letters")
print(myWords)
no capital letters
No CAPITAL letters
name error
No capital letters
In the code snippet below, what is the output generated if the user enters 'Fortnite'?
game = input("enter a game")
print(game, "your score is", score)
score = 37856
Fortnite your score is 37856
SyntaxError
NameError
TypeError
A function in Python can have ____ parameter(s).
no
as many as needed
only 3
only 1
If a Python function is defined as below, which call(s) would be legal?
def library(book, price = 6.95):
other code as needed
library( )
library("Calculus book", 14.99)
library("Accounting Book", 67, $6.95)
library("Mad Magazine", 4.99, 10)
Which of the following is true about the use of functions in Python?
Functions don’t provide better modularity for your application
You cannot create your own functions
Functions are reusable pieces of programs
All of the answers are true
Which are the advantages of using functions in Python?
Reducing duplication of code
Decomposing complex problems
Improving clarity of the code
All options are true
If a function doesn’t have a return statement, which of the following does the function return?
int
none
null
str
What is the Python keyword used in EVERY function that the programmer creates.
str
int
def
num
Order the below numbered code lines into the proper sequence so that the program will run without errors.
1. game = input("enter a game")
2. print(game, "your score is", score)
3. score = 199
2,3,1
3,2,1
1,3,2
A function with 2 float parameters could start with which definition?
def 2Numbers(num1, num2):
function addNumbers(num1, num2):
def addNumbers(num1, num2):
Which code below calls the function in the above code?
def tvShow():
print("Game of Thrones")
tvShow()
run.tvShow()
showname()
run tvshow
Python Function return values must be stored in variables.
True
False
Choose the correct output of calling the function below using the following code:
def addNum(num1 = 20):
return num1 + num1
print(addNum(100))
TypeError
NameError
200
50
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
Line 6 is called
function definition
function call
function name
This code has an error. What's the problem?
the parameters in the definition should have quotes since they're strings
the number of arguments in the function call doesn't match the number of parameters in the function definition
python doesn't allow more than one parameter in a function
TJ isn't actually cool.
4. The code block of function always comes after a _______.
;
:
'
#
