AkshAhuja 11b Ip
AkshAhuja 11b Ip
2
3
Program 1 : Write a program to input name of ‘n’ countries and their capital and currency store, it
in a dictionary and display in tabular form also search and display for a particular country.
CODING:
classxi=dict()
i=1
while i<=n:
a=input("enter section:")
classxi[a]=b
i=i+1
print("class",'\t',"section",'\t',"stream name")
for i in classxi:
print("xi",'\t',i,'\t',classxi[i])
OUTPUT :
4
Program 2 :Write a program to input name of ‘n’ countries and their capital and currency store, it
in a dictionary and display in tabular form also search and display for a particular country
CODING:
d1=dict()
i=1
while i<=n:
c=input("enter country:")
cap=input("enter capital:")
d1[c]=[cap,curr]
i=i+1
l=d1.keys()
print("\ncountry\t\t","capital\t\t","currency")
for i in l:
z=d1[i]
print(i,'\t\t',end=" ")
for j in z:
print(j,'\t\t',end='\t\t')
#searching
for i in l:
if i==x:
print("\ncountry\t\t","capital\t\t","currency\t\t")
z=d1[i]
print(i,'\t\t',end=" ")
for j in z:
print(j,'\t\t',end="\t")
break
5
OUTPUT:
6
Program 3 : Write a program to display frequencies of all the element of a list as dictionary.
CODING:
l=[1,1,1,2,2,3,3,3,3,4,5,1]
count = {}
for i in l:
count[i]=count.get(i,0) + 1
print(key,':',value,"times")
OUTPUT:
7
Program 4 : Write a program to accept a sentence and display frequencies of all letters, digits as
dictionary
CODING:
test_str = "I like Mondays"
print ("The count of all characters in I like Mondays is :\n "+ str(res))
OUTPUT:
8
Program 5 : Write a program to create a dictionary with rollno, name ,marks
of ‘n’ students in class11 and display the names of students with marks above
75.
CODING:
print("Create a dictionary with the roll number, name and marks of n students in a class and \n")
result = {}
for i in range(n):
print(result)
print(result[student][0])
OUTPUT:
9
Program 6 :Write a Program in Python, which accepts an numpy array of
integer and divide all those array elements by 7 which are divisible by 7 and
21 12 35 42 18
Content of the array after program :A[O] A[1] A[2] A[3] A[4]
3 36 5 6 54
CODING:
import numpy as np
a = np.array([21,12,35,42,18])
for i in range(a.size):
if a[i]%7==0:
a[i]=a[i]/7
else:
a[i]=a[i]*3
OUTPUT:
10
Program 7 : Write a program in Python which accepts an integer numpy
array and replaces elements having even values with its half and elements
CODING:
import numpy as np
l=[]
for i in range(5):
l.append(a)
a=np.array(l)
for i in range(a.size):
if a[i]%2==0:
a[i]=a[i]/2
else:
a[i]=a[i]*2
OUTPUT:
11
Program 8: Write a program that would accept a one dimensional integer
array and rearrange the array in such a way that the values of alternate
Example : If the array initially contains {2, 5, 9, 14, 17, 8, 19, 16},
then after rearrangement the array should contain {5, 2, 14, 9, 8, 17, 16,
19}
CODING:
import numpy as np
i=0
while i<a.size:
a[i],a[i+1]=a[i+1],a[i]
i=i+2
OUTPUT:
12
Program 9 : Write a program in Python that declare a 1-d numpy array , and
should display the sum of even values and sum of odd values of the array
separately.
25 20 22 21 53
CODING:
import numpy as np
print(a)
i=0
s1=0
s2=0
while i<a.size:
if a[i]%2==0:
s1=s1+a[i]
else:
s2=s2+a[i]
i=i+1
OR
import numpy as np
print(a)
i=0
s1=0
13
s2=0
b=(a[a%2==0])
s1=sum(b)
s2=sum(a[a%2==1])
OUTPUT:
14