wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Tynker Python Lesson 1-2

Total questions: 30

Worksheet time: 17mins

Name
Class
Date
1.

An identifier cannot begin with a number. Which of the following is NOT a valid identifier?

a)

num

b)

_num

c)

NUM

d)

1num_

2.

An identifier can begin with an underscore (“_”).

a)

True

b)

False

3.

An identifier can begin with a number.

a)

True

b)

False

4.

In Python, an identifier may begin with an underscore or a letter. Which of the following is a valid identifier? Select all that apply.

a)

_total

b)

2_count

c)

NUM_COUNT

d)

dollar_sign

5.

Which of the following is a valid function call?

a)

forwad)

b)

tu-left()

c)

forward()

d)

forward(;

6.

Select the following function calls that are invalid.

a)

ford)(

b)

$forDS()

c)

forward()

d)

turn_left()

7.

How would you call a function named “my_function”?

a)

Call my_function()

b)

my_function

c)

my_function))

d)

my_function()

8.

Identifiers in Python are case-sensitive.

a)

True

b)

False

9.

78090 is a valid identifier in Python.

a)

True

b)

False

10.

Select the following invalid identifiers. (Identifiers are only allowed to start with an underscore or letter.)

a)

&ident

b)

1ident

c)

_ident

d)

-ident

11.

How would you move an object forward 3 times?

a)

forward() forward() forward()

b)

forward() * 3

c)

Call_forward() 3 times

d)

forward() {3}

12.

You are not able to call the same function twice in a row.

a)

True

b)

False

13.

You can replace the parentheses on a function call with square brackets.

a)

True

b)

False

14.

The parentheses at the end of a function call are optional.

a)

True

b)

False

15.

'''Which of the following is the correct way to start a multi-line comment?

a)

'''

b)

/*

c)

#

d)

//

16.

Both of the following are valid ways to comment code:

Both of the following are valid ways to comment code:

# hello

# world

' ' 'hello world' ' '

a)

True

b)

False

17.

Which of the following comments are correct? Select all that apply.

a)

// hello

b)

# hello

c)

/*he

llo */

d)

//he

llo//

18.

Commented lines affect the execution of your program.

a)

True

b)

False

19.

What is the error in this code?

What is the error in this code?

''' This function does something '''

def foo() :

print("hello world") ''' prin

a)

The single line comment must use # instead of '''

b)

The end of the multi-line comment cannot be on its own line

c)

The beginning and end of the multi line comments are incorrect

d)

All answers are errors in the code

20.

How many blocks will the character move using the following code?

for i in range(1,5) :

forward()

a)

3

b)

4

c)

5

d)

6

21.

Which "for" loop will move your character 5 times?

a)

for i in range(1,5) : forward()

b)

for i in range(5) : forward()

c)

for i in range(1,3) : forward()

d)

for i in range(2,5) : forward()

22.

The following "for" loop has correct syntax.

for rang(1,1) :

forward()

a)

True

b)

False

23.

How many times will “function1” be called?

for i in range(10) :

for j in range(10) :

function1()

a)

25

b)

20

c)

50

d)

100

24.

Which is the correct syntax to make a "for" loop run for all numbers from 0 to 10?

a)

for i in range(1,10) :

b)

for i in range(10) :

c)

for i in range(-10) :

d)

for i in range(11) :

25.

The following loop will go from i = 5 to i = 1.

for i in range(5,0,-1)

a)

True

b)

False

26.

"For" loops can increment upwards or downwards.

a)

True

b)

False

27.

Choose the following "for" loops that repeat 5 times. Mark all that apply.

a)

for i in range(5)

b)

for i in range(1,5)

c)

for i in range(5,10)

d)

for i in range(10,2)

28.

Select the invalid "for" loops.

a)

for i in range(5) :

b)

for 2 in range(5) :

c)

for i in range() :

d)

for i in range(5,-1) :

29.

How many times will the following "for" loop execute?

for i in range(10,5,-1) :

a)

20

b)

10

c)

5

d)

0

30.

Why should you indent your code?

a)

In Python, the program’s execution changes based on whether you indent or not

b)

Code that is not indented properly will produce syntax errors

c)

It is much easier to read indented code

d)

All of the above