wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Intro to Python by AUG Problem solving module

Total questions: 24

Worksheet time: 14mins

Name
Class
Date
1.

What symbol do you use to make a comment in one line in Python?

a)

#

b)

''

c)

$

d)

!

2.

Which of the following is constructed by placing expressions within square brackets?

a)

Lists

b)

Classes

c)

Tuples

d)

sets

3.

For strings, the + operator represents

a)

Concatenation

b)

Appending

c)

Addition

d)

Recantation

4.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

5.

str1="helloworld"

print(str1[ : :-1])

a)

worldhello

b)

hello

c)

helloworld

d)

dlrowolleh

6.

>>>"abcd"[2:]

a)

ab

b)

a

c)

cd

d)

dc

7.

>>>i = 2

           >>>while True:

                                   if i%3 == 0:

                                              break

                             print(i)

                            i += 2

a)

2 4

b)

2  3

c)

error

d)

 2 4 6 8 10 …

8.

Q4.

What is the order of precedence in Python?

1. Subtraction

2. Exponential

3. Multiplication

4. Division

5. Addition

6. Parenthesis

Enter the numbers in the right order

(a)  

9.

Choose the correct syntax of the split function:

a)

x.split[]

b)

X.SPLIT(",", 3)

c)

x.split(",", 3)

d)

split(x)

10.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

11.

The program above prints the sum of all the numbers between 0 and 101 that are

a)

alternate odd numbers

b)

alternate even numbers

c)

alternate numbers

12.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

13.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

14.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

15.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

16.

Select all the correct options to copy a list


aList = ['a', 'b', 'c', 'd']

a)

newList = copy(aList)

b)

newList = aList.copy()

c)

newList.copy(aList)

d)

newList = list(aList)

17.

What would this code return on the shell?

a)

Nothing

b)

An error

c)

"Woo hoo, you scored!"

d)

"Raheem"

18.

Suppose list1 is [1, 5, 9], what is sum(list1) ?

a)

1

b)

9

c)

15

d)

none

19.

Which of the following commands will return the length of the list mylist?

a)

length(mylist)

b)

len(mylist)

c)

mylist.length()

d)

mylist.len()

20.

What is the output of program below?


motorcycles = ['honda', 'yamaha', 'suzuki']

motorcycles.sort()

print(motorcycles)

a)

['honda', 'yamaha', 'suzuki']

b)

['yamaha', 'suzuki', 'honda']

c)

['honda', 'suzuki', 'yamaha']

d)

['suzuki', 'yamaha', 'honda']

21.

print("abcdef".find("cd"))

a)

2

b)

3

c)

Error

d)

True

22.

print("Hello {} and {}".format('foo', 'bin'))

a)

Hello {} and {}

b)

Hello and

c)

Hello {}

d)

Hello foo and bin

23.

What will be the output of the following Python code snippet?

x = [i**+1 for i in range(3)]; print(x);

a)

[0, 1, 2]

b)

error, ‘;’ is not allowed

c)

error, **+ is not a valid operator

d)

[1, 2, 5]

24.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error