wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basic II

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

In Python, a variable must be declared before it is assigned a value:

a)

False

b)

True

2.

Which of the following statements assigns the value 100 to the variable x in Python:

a)

let x = 100

b)

x = 100

c)

x << 100

d)

x ← 100

e)

x := 100

3.

In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type:

a)

False

b)

True

4.

Consider the following sequence of statements:


n = 300

m = n


Following execution of these statements, Python has created how many objects and how many references?

a)

One object, one reference

b)

Two objects, one reference

c)

Two objects, two references

d)

One object, two references

5.

What is the output of the following code:


x = 5

y = "John"

print(x + y)

a)

5 John

b)

x John

c)

Error because x and y are from two different type of data

d)

Error because 5 does not have quotation mark

6.

Which of the following are valid Python variable names:

a)

home_address

b)

route66

c)

4square

d)

ver1.3

e)

Age

7.

You are reading Python code, and these statements appear scattered in different locations throughout the code:


employeenumber = 4398

.

.

.

EmployeeNumber = 4398

.

.

.

employeeNumber = 4398

a)

These statements refer to different variables.

b)

These statements refer to the same variable.

8.

Create a variable named carname and assign the value Volvo to it.

a)

Volvo = carname

b)

Volvo = "carname"

c)

carname = "Volvo"

d)

carname = 'Volvo"

e)

carname = Volvo

9.

Create a variable named x and assign the value 50 to it. The value, 50 is in string type.

a)

x = 50

b)

50 = "x"

c)

x = "50"

d)

x (50)

10.

What symbol is used to access elements of the string?

a)

Curly bracket { }

b)

Round bracket ( )

c)

Square bracket [ ]

11.

What is the output of the following code?


a = "I am cute

print(a[3)

a)

c

b)

m

c)

space

d)

cute

12.

What is the output of the following code:


b = "Programming is fun!"

print(b[2:7)

a)

ogram

b)

ogramm

c)

gram

d)

gramm

13.

a = "Good Morning!"

print(len(a))

a)

13

b)

12

c)

11

d)

14

14.

a = "Hello, World!"

print(a.lower())

a)

hello, World!

b)

HELLO, WORLD!

c)

hello, world!

d)

Error

15.

a = "Hello, World!"

print(a.replace("H", "J"))

a)

Jello, World!

b)

jello, World!

c)

JELLO, WORLD!

d)

jello, world!

16.

a = "Hello, World!"

b = a.split(",")

print(b)

a)

{'Hello, World!'}

b)

('Hello, World!')

c)

['Hello', ' World!']

d)

['Hello'],['World']

17.

x = 7

y = 2


print(x % y)

a)

3

b)

7

c)

4

d)

1

18.

x = 3

y = 3


print(x ** y

a)

27

b)

9

c)

0

d)

81

19.

x = 23

y = 3


print(x // y)

a)

7

b)

7.6666

c)

7.7

d)

Error

20.

What is the output of the following code:


age = 36

txt = "My name is John, I am " + age

print(txt)

a)

My name is John, I am

b)

My name is John, I am 36

c)

Error