wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Fundamentals and Programming

Total questions: 13

Worksheet time: 10mins

Name
Class
Date
1.

What will be the output?


>>>t = (1, 2)

>>>2 * t

a)

(1, 2, 1, 2)

b)

[1, 2, 1, 2]

c)

(1, 1, 2, 2)

d)

(2,4)

2.

t = (1, 2, 4, 3, 8, 9)

print([t[i] for i in range(0, len(t), 2)])

a)

[2, 3, 9]

b)

(1, 4, 8)

c)

[1, 4, 8]

d)

[1, 2, 4, 3, 8, 9]

3.

What is the output of the following piece of code when executed in Python shell?


>>> a=("Check")*3

>>> a



a)

(‘Check’,’Check’,’Check’)

b)

* Operator not valid for tuples

c)

(‘CheckCheckCheck’)

d)

Syntax error

4.

What is the output of the following code?


>>> a=(2,3,4)

>>> sum(a,3)

a)

Too many arguments for sum() method

b)

The method sum() doesn’t exist for tuples

c)

12

d)

Synatx Error

5.

Is the following piece of code valid?


>>> a=(1,2,3,4)

>>> del a

a)

No because tuple is immutable

b)

Yes, the entire tuple is deleted

c)

No, invalid syntax for del method

d)

Yes, first element in the tuple is deleted

6.

What type of data is: a=[(1,1),(2,4),(3,9)]?

a)

Array of tuples

b)

List of tuples

c)

Tuples of lists

d)

Invalid type

7.

write q python function to print the sum of digits of a given number

4 lines
8.

write a python function test_prime() to find weather a given number is prime or not

4 lines
9.

write a python program to print all the prime numbers in a given range. Use the function test_prime() that you have created.

4 lines
10.

Suppose there is a list such that: l=[2,3,4].

If we want to print this list in reverse order, which of the following methods should be used?

a)

reverse(l)

b)

list(reverse[(l)])

c)

reversed(l)

d)

list(reversed(l))

11.

Which of the following functions does not throw an error?

a)

ord()

b)

ord(”)

c)

ord(‘ ‘)

d)

ord(“”)

12.

What is the output of the function shown below?


>>>oct(7)

>>>oct(‘7’)

a)

Error

07

b)

0o7

Error

c)

07

Error

d)

07

0o7

13.

What is the output of the below program ?


x = 50

def func(x):

print('x is', x)

x = 2

print('Changed local x to', x)

func(x)

print('x is now', x)

a)

x is now 50

b)

x is now 2

c)

x is now 100

d)

None of the above