Font size
WorksheetsPython Fundamentals and Programming
Total questions: 13
Worksheet time: 10mins
What will be the output?
>>>t = (1, 2)
>>>2 * t
(1, 2, 1, 2)
[1, 2, 1, 2]
(1, 1, 2, 2)
(2,4)
t = (1, 2, 4, 3, 8, 9)
print([t[i] for i in range(0, len(t), 2)])
[2, 3, 9]
(1, 4, 8)
[1, 4, 8]
[1, 2, 4, 3, 8, 9]
What is the output of the following piece of code when executed in Python shell?
>>> a=("Check")*3
>>> a
(‘Check’,’Check’,’Check’)
* Operator not valid for tuples
(‘CheckCheckCheck’)
Syntax error
What is the output of the following code?
>>> a=(2,3,4)
>>> sum(a,3)
Too many arguments for sum() method
The method sum() doesn’t exist for tuples
12
Synatx Error
Is the following piece of code valid?
>>> a=(1,2,3,4)
>>> del a
No because tuple is immutable
Yes, the entire tuple is deleted
No, invalid syntax for del method
Yes, first element in the tuple is deleted
What type of data is: a=[(1,1),(2,4),(3,9)]?
Array of tuples
List of tuples
Tuples of lists
Invalid type
write q python function to print the sum of digits of a given number
write a python function test_prime() to find weather a given number is prime or not
write a python program to print all the prime numbers in a given range. Use the function test_prime() that you have created.
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?
reverse(l)
list(reverse[(l)])
reversed(l)
list(reversed(l))
Which of the following functions does not throw an error?
ord()
ord(”)
ord(‘ ‘)
ord(“”)
What is the output of the function shown below?
>>>oct(7)
>>>oct(‘7’)
Error
07
0o7
Error
07
Error
07
0o7
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)
x is now 50
x is now 2
x is now 100
None of the above
