0% found this document useful (0 votes)
26 views

CH2

Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

CH2

Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

TAAC

GRADE : XII WORKSHEET - 2 SUB : COMPUTER SCIENCE


PYTHON REVISION TOUR – 2
1. which of the following is not a Python legal string operation?
(a)‟abc‟+‟abc‟ (b) “abc‟*3 (c)‟abc‟ + 3 (d)‟abc‟.lower ()
2. Out of the following operators, which ones can be used with strings?
=, -, *, /, //, %, >, <>, in, not in, <=
3. What would following expression return?
(a) ”Hello World”.upper().lower() (b) ”Hello World”.lower().upper()
(c) ”Hello World”.find(“Wor”,1,6) (d) ”Hello World”.find(“Wor”)
(e) ”Hello World”.find(“wor”) (f) ”Hello World”.isalpha()
(g) ”Hello World”.isalnum() (h) “123FGH”.isdigit
(i) ”Hello World”.isdigit()
4.Write a python script that traverses through an input string and prints its characters in
different lines – two characters per line.
5. Find the output – if we give input as “Hello”

6. WAP that:
 Prompt the user for a string
 Extract all the digits from the string.
 If there are digits
 Sum the collected digits together.
 Printout:
 The original string
 The digits
 The sum of the digits
 If there are no digits
 Print the original string
 A message “Has no Digits”
7. Start with the list[8,9,10]. Do the following using list functions
(a) Set the second entry (index 1) to 17
(b) Add 4, 5 and 6 to the end of the list.
(c) Remove the first entry from the list.
(d) Sort the list.
(e) Double the list.
(f) Insert 25 at index 3.
8. If a is [1, 2, 3], what is the difference (if any) between print( a*3 ) and print [a, a, a]?
9. If a is [1, 2, 3], what is the meaning of a [1:2] = 4 and a [1:1] = 4?
10.Consider L = [ 2 , 4, ,6 , 8, 10] WAP to display the list as [ 4 , 6, , 8, 10 , 2 ]
11.

12.

13.

14.

15.
16. WAP to calculate the mean of the numbers in the given tuple.

17. Write Python script to display the element with minimum value from the given tuple.
18. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for k in d:
print (k, '=', d[k])
19. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for k in d.keys():
print (k, '=', d[k])
20. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for v in d.values():
print (v, end=" ")
21. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for v in d.items():
print (v[0], ":", v[1])
22. Write the output of following code:
x = {1:10}
d = {2:20, 3:30, 4:40}
x.update(d)
print(x)
23. consider d = { 1 : [ 10 , 20 , 30] , 2 : [ 40 , 50 , 60 ], 3 : [ 70 , 80 , 90 ] } WAP to display the
keys with its corresponding values’ average.
24. Predict the output :
e = “ Hello Good Morning”
s = e.split(“ “ )
print(s[ : : 3]
25. What will be the output?
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
a) 30 b) 24 c) 33 d) 12
Rough Space

You might also like