[go: up one dir, main page]

0% found this document useful (0 votes)
2 views4 pages

python class_12_1 (1)

The document contains a series of programming questions and tasks related to Python, including identifying valid identifiers, manipulating lists, and writing functions. It also includes code snippets for predicting outputs, rewriting loops, and handling dictionaries. The tasks cover a range of topics such as string manipulation, list operations, and basic input/output handling.

Uploaded by

Naren Paramanik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

python class_12_1 (1)

The document contains a series of programming questions and tasks related to Python, including identifying valid identifiers, manipulating lists, and writing functions. It also includes code snippets for predicting outputs, rewriting loops, and handling dictionaries. The tasks cover a range of topics such as string manipulation, list operations, and basic input/output handling.

Uploaded by

Naren Paramanik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) Find the Valid identifier(s)

a) A$B b) Si-12 c) none d) COVID-19

2) Given the lists L=[1,3,6,82,5]


print(L[:-3 ] + L [len(L)%4 :])

3) Write a statement in python to declare a dictionary whose keys are ‘Harddisk’,’Pendrive’,’Mouse’ and
values are 5000, 650 and 875 respectively

4) Predict the output:


L= ["These", ["are", "a"],["few", "words"],"that" ,"we", "will", "use"]
a) L[3:4]+L[1:2] b) "few" in L[2:3]

5) Identify the valid declaration of M:


m = [[‘Jan’, ‘31’],[‘Feb’, 28]]

a) dictionary b) string c) nested tuple d) nested list

6) If the following code is executed, what will be output of the following code ?
Name =”Python-string_slicing”
print(name[-10 : 15])

7) A python statement generates the following output :- SFRE


a) x=(“ASDFGRTEHYT” [1:8:2]) [1:4]
b) x=(“ASDFGRTEHYT” [0:8]) [0:4:2]
c) x=(“ASDFGRTEHYT” [1:9:2]) [0:4]
d) x=(“ASDFGRTEHYT” [1:10]) [0:4]

8) What is the output of the following code.


for i in range (2,6,2):
print(i*'$')

10) List1=[15,25,35,40]
a) Display maximum value from the given list
b) To remove the 2nd and 3 rd element from the given list

11) Write the output of the following code. How many times will the following loop iterate ?
for j in “absolute”:
if i>=’t’ :
break
print(j, end= ‘ ‘)

12) Rewrite the following code using while loop


a=int(input(“enter base”))
b=int(input(“Enter poser”))
s=1
for i in range(b) :
s*=a
print(s)

13) Write the output


L= [ ]
L1= [ ]
L2 = [ ]
for i in range (16,10):
L.append(i)
for i in range (20,4, -2):
L1.append(i)
for i in range len(L1)):
L2.append(L[i] + L1[i])
L2.append(len(L)-len[L1])
print(L2)

14) Rewrite the correct program and underline the errors :

d1=dict[ ]
i=1
n = input(“Enter number of records :”)
while i <=n :
a= input(“Enter name of the student:”)
b= input(“Enter phone number of the Employee :”)
d1(a)=b
i = i +1
l =d1.key[ ]
for i in l :
print(i, ‘\t’,’dl[i]’)

15) What is the output produced by the following code?


x=1
if x>3:
if x>4:
print('A',end='#')
else:
print('B',end='$' )
elif x<2:
if (x!=0):
print('C', end='@' )
print('D')

16) Predict the output of the code given below:

s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)
16) Write the program in Python to shift the negative numbers to left and the positive numbers to right so that
the resultant list will be as follows :
Original list [-2,1,-3,-15,16,-17,5,-3,-6]
Output should be [1,16,5,-6,-3,-17,-15,-3,-2]
17) Write a python program to input names of ‘n’ employees and their basic . Calculate house rent (30% of
basic salary ) , conveyance allowance(1% of basic salary), PF(9% of basic salary) and (gross salary = basic
salary + house rent + conveyance allowance - PF). Also display all the details.

18) Predict the output of the given code:


dic_str = {‘S’: “Science” , ‘N’ : “Non-Medical” , ‘C’ : “Commerce” , ‘A’ : “Arts”}
len(dic_str)
dic_str.keys( )
print(dic_str.get(‘V’))
dic_str[‘V’] = “Vocational”
print(dic_str)
del dic_str[‘N’]
print(dic_str.values( ))

19) Write a Python program to convert month name to a number of days.


Example Output
List of months: January, February, March, April, May, June, July, August,
September, October, November, December
Input the name of Month: April
Number of days: 30 days

You might also like