wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Intermediate Python

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Your Mindset Right now

a)
b)

c)

d)

2.

Create a variable named bike and assign the value Kawasaki H2R to it

a)

bike= Kawasaki H2R

b)

"bike" = Kawasaki

c)

H2R bike= "Kawasaki H2R"

d)

"KawasakiH2R"= bike

3.

Create a variable named x and assign the value of integer 50 to it

a)

x="50"

b)

x: 50

c)

"x"=50

d)

x=50

4.

Display the sum of 5 + 10, using two variables: x and y

a)

x=y y = 10

print(x +y)

b)

x=5 y = x

print(x +y)

c)

x=10 y =5

print(x +y)

d)

x=5 y =10

print(x +y)

5.

Select the illegal variable name

a)

2my-first_name = "John"

b)

my-firstname = "John"

c)

__my-first_name = "John"

d)

my2-first_name = "John"

6.

What is used to print the length of a string

a)

len()

b)

length()

c)

type.legth()

d)

fulllength()

7.

What can we use to get the first character of a string txt= "Banana"

a)

x=txt(0)

b)

x=txt(1)

c)

x=txt[0]

d)

x=txt[1]

8.

What can we use to get the characters from index 2 to index 4 (llo) in txt = "Hello, World"

a)

Options

x= txt[2:4]

b)

x= txt[1:4]

c)

x= txt[2:5]

d)

x= txt[2:6]

9.

Select the right syntax for the if condition

a)

a=10 b=20 if a is greater than b: print("Hello World")

b)

a=10 b=20 if a>b: print("Hello World")

c)

a=10 b=20 if a>b; print("Hello World")

10.

Fill in the blank if a> b: print("True") _____: print("False")

a)

otherwise:

b)

then:

c)

else:

d)

elif:

11.

Select the right syntax to create a function called my_function

a)

def my_function:

b)

define my_function:

c)

func my_function;

d)

create funct my_function;

12.

Inside a function with two parameters, print the first parameter. def my_function(fname, lname): print(________)

a)

my_function

b)

fname

c)

lastname

d)

lname

13.

What will be the output of the following program: fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": print(x)

a)

cherry

b)

apple

c)

apple cherry

d)

banana

14.

The following code will stop the loop if i is 3 Fill in the blanks to perform the same i = 1 ______ i < 6: if i == 3: break i += 1

a)

do while

b)

for

c)

if

d)

while

15.

What will be the output for the following code: for x in range(6): print(x)

a)

0 1 2 3 4 5 6

b)

1 2 3 4 5 6

c)

0 1 2 3 4 5

d)

1 2 3 4 5