wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Assignment 1

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Who discovered python? 

 

a)

Wick ran Rossum 

b)

Guido Van Rossum

c)

Rasmus Lerdrom

d)

Niene stom 

2.

Which of the following is the correct extension of the Python file? 

a)

.python

b)

.py

c)

.pl

d)

.p

3.

 Which of the following character is used to give single-line comments in Python? 

a)

//

b)

#

c)

/*

d)

!

4.

How do you declare a variable in Python?

a)

var name = "value"

b)

define name = value

c)

name = "value"

d)

You don't need to declare variables in Python

5.

What is the output of the following code: x = 1 + 2 * 3 

a)

9

b)

6

c)

Error

d)

7

6.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]? 

a)

[2, 33, 222, 14]

b)

error

c)

25

d)

 [25, 14, 222, 33, 2]

7.

What is the value of x 

x=0 

while(x<100): 

x+=2 

print(x)

a)

101

b)

99

c)

None of the above,this is an infinite loop

d)

100

8.

What is the output of the following nested loop?

for num in range(10, 14): 

   for i in range(2, num): 

       if num%i == 1: 

       print(num) 

          break

a)

10

11

12

13

b)

10

11

12

c)

11

12

13

d)

None of these 

9.

if -3 will evaluate to True?

a)

True

b)

False

10.

Given the nested if-else structure below, what will be the value of x after code execution completes 

 

x = 0 

a = 0 

b = -5 

if a > 0: 

    if b < 0:  

        x = x + 5  

    elif a > 5: 

        x = x + 4 

    else: 

        x = x + 3 

else: 

    x = x + 2 

print(x)

a)

2

b)

0

c)

3

d)

4

11.

What is the output of the following loop ?

for l in 'Jhon': 

   if l == 'o': 

      pass 

   print(l, end=", ")

a)

J,h,n,

b)

J,h,o,n,

c)

J,h,o,n

d)

J,o,n

12.

What is the value of the var after the for loop completes its execution 

 

var = 10 

for i in range(10): 

    for j in range(2, 10, 1): 

        if var % 2 == 0: 

            continue 

            var += 1 

    var+=1 

else: 

    var+=1 

print(var)

a)

20

b)

21

c)

10

d)

30

13.

Match the following 

1.List                                                                 a.unordered collection of unique elements 

2.tuple                                                          b.Ordered collection of elements 

3.Dictionary                                                c.Immutable collection of elements 

4.set                                                             d.Efficient Membership testing(Existence check) 

a)

1-a,2-b,3-c,4-d

b)

1-b,2-c,3-d,4-a

c)

1-b,2-a,3-d,4-c

d)

1-c,2-b,3-a,4-d

14.

What will be the output of the following code? 

var=(4) 

print(type(4))

a)

class<’list’>

b)

class<’int’>

c)

class<’tuple’> 

d)

None of the above 

15.

Match the Following

1)keys() a) Returns a view of all keys in the dictionary.

2)values() b) Returns a view of all values in the dictionary.

3)items() c) Returns a view of all key-value pairs as tuples.

4)get(key, default=None) d) Returns the value for the given key, or a default value if the key doesn't exist

a)

1-a,2-b,3-c,4-d

b)

1-b,2-a,3-c,4-d

c)

1-c,2-b,3-a,4-d

d)

1-a,2-c,3-b,4-d

16.

Which of the following codes does not give error on type conversions?

a)

tuple(4)

b)

tuple(4,) 

c)

tuple(‘4’)

d)

None of the above

17.

Imagine you're working on a program for a college registrar's office. The program needs to efficiently check if a student is registered for a specific course. Students are identified by their ID numbers.  Which data structure would be the most efficient for storing student enrollments, considering the trade-offs between lists, dictionaries, and sets?

a)

List

b)

Dictionary (Hash table)

c)

Set

d)

All of the above 

18.

What will be the output of the following code? 

 

print((1,2,3)+(‘a’,’b’,’c’))

a)
  1. (1, 2, 3, 'a', 'b', 'c')

b)
  1. ((1,2,3),(‘a’,’b’,’c’))

c)

(1,’a’,2,’b’,3,’c’) 

d)
  1. None of the above 

19.

 

  • Which of the following cannot be an element of a set?

a)

List

b)

tuple

c)

Dictionary

d)

Both a and c

20.

Which data structure is used pass arguments to functions without allowing modifications?

a)

set

b)

list

c)

Dictionary

d)

tuples