NEW
Font size
WorksheetsPython Training
Total questions: 22
Worksheet time: 11mins
What would the output be if you run the code below?
25
30
25
25
This would give you an error because x already has a value when we de x = 30
Which of these is not a valid Python variable name?
myVariable
my_variable
_var
1st_variable
Why would you write a variable name in all uppercase (all capital letters) in Python?
There's no reason to ever do this in Python. It's the wrong style.
To signal that you don't intend for this variable's value to change.
When defining important values that will be used throughout the entire code.
What would the output be (i.e. what would the user see) from this code sample?
The user would see nothing.
6
This would result in an error, because you can't use underscores in variable names.
What would the value of div be at the end of this segment?
4
3.5
3
What would the value of x be at the end of this code segment?
7.5
7
8
What would the user see after running this code segment?
Hello, Jose
'Hello, Jose'
"Hello, Jose"
The user would see nothing, or there would be an error.
What would the user see if they executed this segment of code?
How are you, Jose?
'How are you, Jose?'
They would see an error.
They would see nothing printed out.
What would the output of this code be?
There would be an error, because we've tried to put a number into a string.
There would be an error, because we've got multiple placeholders.
Bob is Bob years old.
Bob is Bob years old.
30 is 30 years old.
Bob is 30 years old.
What would the value of double be after running this code segment?
Assume the user enters 3 when asked to enter something.
'33'
'6'
Nothing. The user would get an error.
Your number doubled is 6.
What would the value of cmp be at the end of this code segment?
It would be an error, you cannot have 18 after an and.
18
True
False
What would the result of cmp be after running this code segment?
True
False
There would be an error because you can't use multiple comparisons on one line.
What does or do?
It returns True if either value is True.
It returns True only if both values are True.
It return the value after the or, if the value before the or evaluates to False.
Replace the ??? line with one of the answers to complete an example of password authentication:
user_input = input("Password : ")
input("Password")
user_input = input
user_input : input ("Password : ")
The below is not working Python code, but it represents a pattern of what we could do in Python (some call it pseudocode). Can you fill in the missing word, represented by ____ ?
else if
elif
else
Given this code, what would the value of doubled be at the end of the segment?
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 2, 4, 6, 8]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Given this list:
How would you create a new list where all the names are uppercase?
(you may have to do some research as to what the correct way of turning a string into uppercase is!)
[name.lower() for name in guests]
[name.uppercase() for name in guests]
[name.upper() for name in guests]
[NAME for name in guests]
What is a function?
A series of instructions that execute top to bottom.
A block of code that you can run at any point after it has been defined, and that produces an output or performs an action. Sometimes it can take inputs as well.
Something that takes inputs and gives outputs.
What would the output of this segment of code be?
Hey there Rolf
Nothing would be printed out.
This would give an error, because the function was not called.
What would the values of x and y be after this segment of code ?
This would result in an error, because hi() doesn't return anything.
How would you write this function as a lambda function?
How would you write this function as a lambda function?
def to_uppercase(name):
return name.upper()
lambda to_uppercase(name): name.upper()
lambda name : name.upper()
lambda : arg.upper()
