Ekansh Practical File XII-A
Ekansh Practical File XII-A
Ekansh Practical File XII-A
1. Write a program to read two lists, L1 and L2 from user. Now merge L1 and L2 and
print “mostly odd” if merged list contains more odd numbers than even numbers
else it should print “mostly even”
L1=eval(input("Enter list 1"))
L2=eval(input("Enter list 2"))
L=L1+L2
m=0
n=0
for i in L:
if i%2==0:
n=n+1
else:
m=m+1
if n>m:
print("Mostly Even")
else:
print("Mostly Odd")
Output
Code:
while True:
s= input("Enter the string")
print("1. To count the no. of uppercase and lowercase alphabets.")
print("2. To check if the string is palindromic")
print("3. To check repeating characters (yes/no)")
print("4. To count special characters (any non alphanumeric character is special")
print("5. Exit")
ch=int(input("Enter the Choice"))
if ch==1:
u=0
l=0
for i in s:
if i.isupper():
u+=1
elif i.islower():
l+=1
print("UpperCase=", u)
print("LowerCase=", l)
elif ch ==2:
if(s == s[:: - 1]):
print("It is palindromic")
else:
print("It is not palindromic")
elif ch==3:
duplicate=[]
for a in s:
if s.count(a)>1:
print('Yes',a ,"is the repeating
character")
elif ch==4:
for b in s:
if not(b.isalnum()):
print ("Special Characters:" , b)
elif ch==5:
break
3. Write a python program to input ‘n’ names and phone numbers to store it in a
dictionary with names as keys paired with their phone numbers as values. Your code
should now print the following:
Code:
n=int(input("Enter the number of entries"))
d={}
for i in range(n):
name=input("Enter the name")
pno= int(input("Enter the Phone Number"))
d[name]=pno
print(d)
print("1. Search Name")
print("2. Search Phone Number")
ch=int(input("Enter the Choice"))
if ch==1:
name1=input("Enter the Name of the Person whose number is to be searched")
for j in d:
if j==name1:
print(d[name])
elif ch==2:
pnon=int(input("Enter the Ph No. to find the name"))
for a,b in d.items():
if b==pnon:
print(a)
else:
print("Invalid Input")
Output:
6. Series objects week1, week2, week3, week4 store the temperatures of days of 4 weeks
of a month respectively. Write a script to:
a) Print the average temperature per week
b) Store the average temperature of each day for 4 weeks in another series
AVG_TEMP.
c) Print the maximum temperature from the AVG_TEMP Series
d) Print the minimum temperature from the AVG_TEMP Series
e) Print the days where temperature is above 35 degrees.
days=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
week1=pd.Series(data=[34.5,44.3,68.4,46.5,33.4,34.9,45.6],index=days)
week2=pd.Series(data=[36.5,43.7,69,41.5,31.4,38.9,35.7],index=days)
week3=pd.Series(data=[36.5,44.3,63.4,42.5,39.4,32.9,48.6],index=days)
week4=pd.Series(data=[31.5,54.3,35.4,46.5,33.4,34.9,45.6],index=days)
print('Average of week 1' , week1.mean())
print('Average of week 2' , week2.mean())
print('Average of week 3' , week3.mean())
print('Average of week 4' , week4.mean())
Avg_Temp=(week1+week2+week3+week4)/4
print('average temperature of each day for 4 week:\n',Avg_Temp)
print('maximum temperature :',Avg_Temp.max())
print('Minimum Temperature :',Avg_Temp.min())
print('days where temperature is above 35 degrees')
Avg_Temp[Avg_Temp>35]
f)
Output:
Percentage Grade
91-100 A1
81-90 A2
71-80 B1
61-70 B2
51-60 C1
41-50 C2
33-40 D
<40 E
All the newly created columns (totalmarks, per, grade) should be inserted in the dataframe.
Print the final dataframe.
f={'Roll_No':pd.Series([1,2,3,4,5]),'Name':pd.Series(['Rohan','Anuj','Ekansh','Anshul','Mehul']),'Eng':
pd.Series([67,78,98,75,35]),'Phy':pd.Series([56,78,86,67,78]),'Chem':pd.Series([65,78,70,57,89]),'Mat
h':pd.Series([75,86,58,79,90]),'IP':pd.Series([86,94,76,93,76])}
student=pd.DataFrame(df)
tot=[]
per=[]
grade=[]
for (x,y) in student.iterrows():
total=y['Eng']+y['Phy']+y['Chem']+y['Math']+y['IP']
tot.append(total)
avg_marks=total/5
per.append(avg_marks)
if avg_marks>=91:
grade.append('A1')
elif avg_marks>=81:
grade.append('A2')
elif avg_marks>=71:
grade.append('B1')
elif avg_marks>=61:
grade.append('B2')