wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Training

Total questions: 22

Worksheet time: 11mins

Name
Class
Date
1.

What would the output be if you run the code below?

a)

25

30

b)

25

25

c)

This would give you an error because x already has a value when we de x = 30

2.

Which of these is not a valid Python variable name?

a)

myVariable

b)

my_variable

c)

_var

d)

1st_variable

3.

Why would you write a variable name in all uppercase (all capital letters) in Python?

a)

There's no reason to ever do this in Python. It's the wrong style.

b)

To signal that you don't intend for this variable's value to change.

c)

When defining important values that will be used throughout the entire code.

4.

What would the output be (i.e. what would the user see) from this code sample?

a)

The user would see nothing.

b)

6

c)

This would result in an error, because you can't use underscores in variable names.

5.

What would the value of div  be at the end of this segment?

a)

4

b)

3.5

c)

3

6.


What would the value of x be at the end of this code segment?

a)

7.5

b)

7

c)

8

7.

What would the user see after running this code segment?

a)

Hello, Jose

b)

'Hello, Jose'

c)

"Hello, Jose"

d)

The user would see nothing, or there would be an error.

8.

What would the user see if they executed this segment of code?

a)

How are you, Jose?

b)

'How are you, Jose?'

c)

They would see an error.

d)

They would see nothing printed out.

9.

What would the output of this code be?

a)

There would be an error, because we've tried to put a number into a string.

b)

There would be an error, because we've got multiple placeholders.

c)

Bob is Bob years old.

d)

Bob is Bob years old.

30 is 30 years old.

e)

Bob is 30 years old.

10.

What would the value of double be after running this code segment?

Assume the user enters 3 when asked to enter something.

a)

'33'

b)

'6'

c)

Nothing. The user would get an error.

d)

Your number doubled is 6.

11.

What would the value of cmp be at the end of this code segment?

a)

It would be an error, you cannot have 18 after an and.

b)

18

c)

True

d)

False

12.

What would the result of cmp  be after running this code segment?

a)

True

b)

False

c)

There would be an error because you can't use multiple comparisons on one line.

13.

What does or  do?

a)

It returns True if either value is True.

b)

It returns True only if both values are True.

c)

It return the value after the or, if the value before the or evaluates to False.

14.

Replace the ??? line with one of the answers to complete an example of password authentication:

a)

user_input = input("Password : ")

b)

input("Password")

c)

user_input = input

d)

user_input : input ("Password : ")

15.

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 ____ ?

a)

else if

b)

elif

c)

else

16.

Given this code, what would the value of doubled  be at the end of the segment?

a)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

b)

[0, 2, 4, 6, 8]

c)

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

d)

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]

17.

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!)

a)

[name.lower() for name in guests]

b)

[name.uppercase() for name in guests]

c)

[name.upper() for name in guests]

d)

[NAME for name in guests]

18.

What is a function?

a)

A series of instructions that execute top to bottom.

b)

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.

c)

Something that takes inputs and gives outputs.

19.

What would the output of this segment of code be?

a)

Hey there Rolf

b)

Nothing would be printed out.

c)

This would give an error, because the function was not called.

20.

What would the values of x and y be after this segment of code ?

a)

b)

c)

d)

This would result in an error, because hi() doesn't return anything.

21.

How would you write this function as a lambda function?

a)

b)

c)

22.

How would you write this function as a lambda function?

def to_uppercase(name):

    return name.upper()


a)

lambda to_uppercase(name): name.upper()

b)

lambda name : name.upper()

c)

lambda : arg.upper()