XII Python Fundamentals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Python Fundamentals Worksheet

Roll No:__________ Class: XII


1. What will be the output of the following program?
S1 = "Welcome to JAVA Programming"
S2 = S1.replace("JAVA","Python")
print(S2)
a) Welcome to JAVA Programming b) Welcome to Python
Programming
c) Welcome to Java Python Programming d) None of the above
2. What will be the output of the following program?
Str1 = "Hello"
Str2 = Str1[:-1]
print(Str2)
a) olle b) Hello c) el d) Hell
3. What will be the output of the following program?
S = "ILOVEWORLD"
for ch in range(0, len(S), 3):
print(S[ch], end=" ")
a) I V O D b) I O W L c) I V W L d)I L O V
4. How would you print 'UK' for the given list?
Countries = ['India', 'USA', 'UK']
a) Countries[2] b) Countries[-1:] c) Both a and b d) Only a
5. What will be the output of the following program?
a = '\t\t\tPython\n\n'
print(a.strip())
a) Python\n b) Python\n\n c) Python d) \t\tPython
6. Which of the following is the equivalent of s[:-1]?
a) s[:len(s)] b) s[len(s):] c) s[::] d) S[:-1]
7. What will be the output of the following program?
str1 = 'I love Python programming. Python is very easy.'
print(str1.find("Python"))
print(str1.rfind("Python"))
a) True, True b) 7, 27 c) 6, 26
d) None of the above
8. Consider the list, L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'].
Which one of the following outputs is correct?
a) >>>L[0::3]
['a', 'c', 'f', 'i']
b) >>>L[0:-1]
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
c) >>>L[0:2]
['a', 'b', 'c']
d) None of the above
9. What will be the output of the following statement?
List1 = [[n, n + 1, n + 2] for n in range(0, 3)]
a) [0,1,2] b) [[0, 1, 2],[0, 1, 2],[0, 1, 2]]
c) [[0, 1 , 2],[1, 2, 3],[2, 3, 4]] d) [[0, 1 , 2],[2, 3, 4],[4, 5, 6]]
10. Which of the following is the best way of code to delete element 15 from the
given list?
numbers = [20, 30, 15, 23, 45]
a) numbers[2] = ' ' b) numbers[2].delete() c) del numbers[2]
d)numbers.remove(2)
11. What will be the output of following code?
Numbers = [10, 20, 30]
total = 0
while Numbers:
total = total + Numbers.pop()
print('Numbers = ', Numbers)
print('total = ', total)
a) Numbers = [10, 20, 30], total = 60 b) Numbers = [ ], total = 60
c) Numbers = [ ], total = [ ] d) Numbers = [10, 20, 30], total = 30
12. What will be the output of the following code?
a = ((1, 2),) * 7
print(len(a[3:6]))
a) 2 b) 3 c) 4 d) Error
13. What will be the output after the execution of the following statements?
capital = {'India': 'Delhi', 'SriLanka': 'Colombo'}
capital = list(captial.values())
a) Delhi b) ['Delhi', 'Colombo'] c) ['Colombo']
d) Error
14. What will be the output of the following code?
Fruits = ('Banana', 'Grapes', 'Mango', 'WaterMelon')
print(max(fruits))
print(min(fruits))
a) WaterMelon, Mango b) WaterMelon, Banana
c) WaterMelon, Grapes d) Banana, WaterMelon
15. What will be the output of the following statement?
print(15 + 20 / 5 + 3 * 2 - 1)
a) 19.0 b) 19 c) 12.0 d) 24.0
16. Give Output:
colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
del colors[4]
colors.remove("blue")
colors.pop(3)
print(colors)
a) ['violet', 'indigo', 'green', 'red'] b) ['violet', 'indigo', 'yellow',
'red']
c) ['violet', 'indigo', 'orange', 'red'] d) ['violet', 'indigo', 'green',
'yellow']
17. Write the output of following python code Text="Welcome Python"
L=len(Text)
ntext=""
for i in range (0,L):
if Text[i].isupper():
ntext=ntext+Text[i].lower()
elif Text[i].isalpha():
ntext=ntext+Text[i].upper()
else:
ntext=ntext+"!!"
print (ntext)
a) wELCOME!!PYTHON b) wELCOME!!pYTHON
c) wELCOME!!Python d) none
18. What will be the output after the following statements?
x = 25
if x >= 10 and x <= 15:
print('true')
elif x >= 15 and x <= 25:
print('not true')
elif x >= 25 and x <= 35:
print('false')
else:
print('not false')
a) true b) false c) not true d) not
false
19. What will be the output after the following statements?
x, y = 2, 5
while y - x < 5:
print(x*y, end=' ')
x += 3
y += 4
a) 1045 b) 10 45 c) 34 d) 3 4 10 45
20. What will be the output after the following statements?
x=1
while x < 4:
x += 1
y=1
while y < 3:
print(y, end=' ')
y += 1
a)1 1 2 2 b) 1 1 2 2 3 3 4 4 c) 1 2 3 4 d) 1 2 1 2 1 2
21. What will be the output after the following statements?
for i in range(1,5):
if i == 3:
continue
print(i, end=' ')
a) 1 2 4 b) 1 2 3 4 c) 1 2 d) 1 2 3
22. Which of the following is not a core data structure in Python?
a) List b) Module c) Dictionary d) Tuple

23. What will be the output after the following statements?


b=1
for a in range(1, 10, 3):
b += a + 1
print(b)
a) 14 b) 16 c) 20 d) 25
24. Correct way to declare a variable x of float data type in python:
a) x = 2.5 b) float x = 2.5 c) float(2.5) d) All of the above
25. Names given to different parts of a Python program are ………. .
a) Identifiers b) functions c) Keywords d) literals
26. Data items having fixed value are called ………. .
a) Identifiers b) functions c) Keywords d) literals
27. Which of the following is/are correct ways of creating strings?
a) name = Jiya b) name = ‘Jiya’ c) name = “Jiya” d) name =
(Jiya)
28. Which of the following are keyword(s)?
a) name b) Print c) print d) input
29. Escape sequences are treated as ………. .
a) strings b) characters c) integers d) none of
these
30. Which of the following is an escape sequence for a tab character?
a) \a b) \t c) \n d) \b
31. Which of the following is an escape sequence for a newline character?
a) \a b) \t c) \n d) \b
32. The lines beginning with a certain character, and which are ignored by a
compiler and not executed, are called ……….
a) operators b) operands c) functions d) comments
33. The input( ) returns the value as ………. type.
a) integer b) string c) floating point d) none of these
34. To convert the read value through input( ) into integer type, ……….( ) is
used.
a) floating b) float c) int d) integer
35. To print a line a text without ending it with a newline, ………. argument is
used with print( )
a) sep b) newline c) end d) next
36. The default separator character of print( ) is ……….
a) tab b) space c) newline d) dot
37. Python is____
a) High-Level b) Interpreted c) Object-Oriented d) All
Of The Above
38. Which symbol denotes the python prompt?
a) >>> b) # c) ”’ d) //
39. Which of the following is a valid string literal?
a) “PythonMcq” b) ‘PythonMcq’ c) ”’PythonMcq”’ d) All of these
40. Which line of code produces an error?
a) “PythonMcq” + “12” b) ‘PythonMcq’ + 16
c) 3 + 7 d) ‘PythonMcq’ + “21”
41. How many keywords present in the python programming language?
a) 32 b) 61 c) 33 d) 27
42. Which of the following keywords is not reversed keyword in python?
a) None b) class c) goto d) and
43. What is the output of the following program?
a,b,c=10,20,30
a,c,b=a+b,b+20,c+30
print(b,c,a)
44. What is the output of the following program?
Str=” ” ”Python@
123 #” ” ”
print(len(Str))
45. What is the output of the following program?
Str=” ” ”Python@\
Program\
123 #” ” ”
print(len(Str))
Read the following statement and evaluate the following expressions.
a,b,c=1,20,0
46. d=a+b-25//3**c
print(d)
47. print(a*b//(c+2)**1)
48. print(a>b and a<c or a==1)
49. print(a+b<c or not c==-1)
50. a) print(c>a or c-b<10 and not(c==-1))
b) print(not c==0+50)
c) print((not c==-1)+50)
51. Which of the following is the output of the following python code?
str1="TamilNadu"
print(str1[::-1])
(a) Tamilnadu (b) Tmlau (c) udanlimaT
d) udaNlimaT
52. What will be the output of the following code?
str1 = "Chennai Schools"
str1[7] = "-"
(a) Chennai-Schools (b) Chenna-School (c) Type error
(d) Chennai
53. What will be the output of the given python program?
str1 = "welcome"
str2 = "to school"
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
a. weool b. weol c. well d.
welol
54. Which of the following statement is not correct?
(a) A list is mutable (b) A tuple is immutable.
(c) To append() function is used to add an element.
(d) To extend() function is used in tuple to add elements in a list.
55. If List=[10,20,30,40,50] then List[2]=35 will result
(a) [35,10,20,30,40,50] (b) [10,20,30,40,50,35]
(c) [10,20,35,40,50] (d) [10,35,30,40,50]

You might also like