NEW
Font size
WorksheetsPython Assignment 1
Total questions: 20
Worksheet time: 20mins
Who discovered python?
Wick ran Rossum
Guido Van Rossum
Rasmus Lerdrom
Niene stom
Which of the following is the correct extension of the Python file?
.python
.py
.pl
.p
Which of the following character is used to give single-line comments in Python?
//
#
/*
!
How do you declare a variable in Python?
var name = "value"
define name = value
name = "value"
You don't need to declare variables in Python
What is the output of the following code: x = 1 + 2 * 3
9
6
Error
7
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
[2, 33, 222, 14]
error
25
[25, 14, 222, 33, 2]
What is the value of x
x=0
while(x<100):
x+=2
print(x)
101
99
None of the above,this is an infinite loop
100
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
10
11
12
13
10
11
12
11
12
13
None of these
if -3 will evaluate to True?
True
False
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)
2
0
3
4
What is the output of the following loop ?
for l in 'Jhon':
if l == 'o':
pass
print(l, end=", ")
J,h,n,
J,h,o,n,
J,h,o,n
J,o,n
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)
20
21
10
30
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)
1-a,2-b,3-c,4-d
1-b,2-c,3-d,4-a
1-b,2-a,3-d,4-c
1-c,2-b,3-a,4-d
What will be the output of the following code?
var=(4)
print(type(4))
class<’list’>
class<’int’>
class<’tuple’>
None of the above
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
1-a,2-b,3-c,4-d
1-b,2-a,3-c,4-d
1-c,2-b,3-a,4-d
1-a,2-c,3-b,4-d
Which of the following codes does not give error on type conversions?
tuple(4)
tuple(4,)
tuple(‘4’)
None of the above
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?
List
Dictionary (Hash table)
Set
All of the above
What will be the output of the following code?
print((1,2,3)+(‘a’,’b’,’c’))
(1, 2, 3, 'a', 'b', 'c')
((1,2,3),(‘a’,’b’,’c’))
(1,’a’,2,’b’,3,’c’)
None of the above
Which of the following cannot be an element of a set?
List
tuple
Dictionary
Both a and c
Which data structure is used pass arguments to functions without allowing modifications?
set
list
Dictionary
tuples
