Font size
WorksheetsPython Review
Total questions: 54
Worksheet time: 22mins
How do you write a print statment to print the following string: 'Hello World'?
(a)
How do you write a print statement with a variable called myName?
(a)
How would you write an input statement that sets a variable as the users input
variable == input("Enter a value: ")
variable = input(Enter a value: )
input = ("Enter a value: ")
variable = input("Enter a value: ")
Will this add the number
Yes
No
Select the python math operators that work
x
+
÷
-
/
what types of things can variable be set to?
Boolean
String
Number
All of the above
This will give me an error
True
False
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
Good morning 'Dave'
Good morningDave
Good morning name
Good morning Dave
what are the conditions in python if statements?
else
else/if
elif
if
elf
Which symbols surround a list?
[]
{}
()
||
Which function changes a string to a float?
float()
num()
print()
change()
A list is changeable and unordered
True
False
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
Which code should you use to import a function named abc from a Python module named xyz?
import abc
from xyz import abc
import abc from xyz
import mod xyz fn abc
You are comparing two numerical values in the following operation:
In [1]: 9 ___ 9
Out[1]: True
Which operator correctly completes the operation?
=>
=!
>=
Which statement about local variables is true?
A local variable can be read from the global scope.
You can use the same variable name in multiple functions.
A local variable in one function can be read from another function.
A function can update a global variable in a local scope by using the same name for a local variable and assigning a new value.
Complete the sentence to be true for code running in a Python environment.
A local scope is created...
when a function is created
when a function is called
when a function returns to its caller
when a function is destroyed
When a function calls a subfunction, which variables are maintained in memory? (Choose all that apply.)
The global variables
The function variables
The subfunction variables
Which clause should you use for code that you want to execute regardless of whether an exception is raised?
else
elseif
except
finally
True or False: When handling exceptions, Python code can include an else clause or a finally clause, but not both.
True
False
In what format does a dictionary store information?
(key, value)
[key:value]
{key, value}
{key:value}
True or False: In Python, using the `raise` statement allows the programmer to define and raise their own exception.
True
False
Which two statements about key:value pairs are correct? (Choose two.)
Keys are unique
Values are unique
A value can be associated with multiple keys
Keys within a dictionary must be of the same type
Which of the following statements about tuples is true?
A tuple can contain list elements.
A tuple cannot contain another tuple.
After you define a tuple, you can add elements to it.
You define the elements of a tuple within square brackets.
In which two ways is a tuple like a list? (Choose two.)
Lists and tuples are data structures that can store a sequence of elements.
Lists and tuples are immutable data structures.
Lists and tuples can contain int, float, list, and string elements.
You can reorder the elements of lists and tuples.
Which function can you use to list the contents of the current working directory?
os.chdir()
os.getcwd()
os.listdir()
os.rmdir()
What type of loop should you use to repeat a code process as long as a condition resolves as `True`?
compound
for
nested
while
Which function can you use to test whether an absolute or relative path to a folder is valid?
os.path.commonpath(paths)
os.path.exists(path)
os.path.normpath(path)
os.path.realpath(path)
True or False: An infinite loop is a loop that runs until the value returned by the loop condition is False.
True
False
print("Hello world!\nHello world!")
Hello world!
people = ["John", "Rob", "Bob"]
print (people[1])
what would this result be?
people = ["John", "Rob", "Bob"]
print (people[4])
what would this result be?
holds whole numbers
holds a decimal point in a number
Which operator can be used to check if two values are equal to each other?
==
><
<>
=
How do you create a function called myFunction in Python?
(a)
Python uses indentation to block code into chunks
True
False
What output will the console show, if 15 and 30 are entered by the user?
Syntax error
The sum of the two numbers - 45
The concatenation of the two numbers - 1530
Complier error
Given the nested if-else below, what will be the value x when the code is executed successfully.
0
4
2
3
What will:
answer = input("Give me a number")
print(answer * 5)
output?
An error message
The value of answer multiplied by 5
answer * 5
The value of answer repeated 5 times
What can a variable not start with?
A special character
A capital letter
A number
A lower case letter
What does print("hello) display?
hello
gives you an error
"hello"
"hello
'my name' is a valid variable?
No
Yes
Suppose you write a function. How many times can you call the function in your code?
Once
Not more than the number of commands the function holds
It depends on the function
As many times as you want
Which of the statements below is true about indentation in Python?
Indentation only matters in for loops. Then, everything must be indented one level.
Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.
Indentation always matters in Python. Every statement must be aligned correctly.
Indentation only matters in functions. Then, everything must be indented one level.
Which of the following functions is declared correctly?
Which program below includes no errors?
