0% found this document useful (0 votes)
12 views14 pages

AkshAhuja 11b Ip

Uploaded by

5kkkss9b8x
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)
12 views14 pages

AkshAhuja 11b Ip

Uploaded by

5kkkss9b8x
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/ 14

1

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()

n=int(input("enter total number of section in xi class"))

i=1

while i<=n:

a=input("enter section:")

b=input("enter stream name:")

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

n=int(input("enter number of entries"))

while i<=n:

c=input("enter country:")

cap=input("enter capital:")

curr=input("enter currency of country")

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

x=input("\nenter country to be searched:")

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

for key , value in count.items():

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"

res = {i : test_str.count(i) for i in set(test_str)}

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")

print("display the names of students who have marks above 75.")

result = {}

n = int(input("Enter number of students: "))

for i in range(n):

print("Enter Details of student No.", i+1)

rno = int(input("Roll No: "))

name = input("Name: ")

marks = int(input("Marks: "))

result[rno] = [name, marks]

print(result)

print('Names of students who have got marks more than 75:')

for student in result:

if result[student][1] > 75:

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

multiply other array elements by 3.

Sample Input Date of the array

A[O] A[1] A[2] A[3] A[4]

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])

print("\n the elemnets of a numpy array is ",a)

for i in range(a.size):

if a[i]%7==0:

a[i]=a[i]/7

else:

a[i]=a[i]*3

print ("\nthe elements after change are :",a)

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

having odd values with twice its value.

CODING:
import numpy as np

l=[]

for i in range(5):

a=int(input("enter any no:"))

l.append(a)

a=np.array(l)

print("\nthe elements in a numpy arrar are :",a)

for i in range(a.size):

if a[i]%2==0:

a[i]=a[i]/2

else:

a[i]=a[i]*2

print ("\nthe elements after change are : ",a)

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

locations of the array are exchanged

(Assume the size of the array to be even)

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

a=np.array([2, 5, 9, 14, 17, 8, 19, 16])

print ("\nthe elements of numpy array are :",a)

i=0

while i<a.size:

a[i],a[i+1]=a[i+1],a[i]

i=i+2

print ("\n\nthe elements of numpy array after change are :",a)

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.

Example: if the array VALUES contains

25 20 22 21 53

Then the functions should display the output as:

Sum of even values = 42 (i.e 20+22)

Sum of odd values = 99 (i.e 25+21+53) 4

CODING:
import numpy as np

a=np.array([2, 5, 9, 14, 17, 8, 19, 16])

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

print ("sum os even no=",s1)

print ("sum os odd no=",s2)

OR
import numpy as np

a=np.array([2, 5, 9, 14, 17, 8, 19, 16])

print(a)

i=0

s1=0

13
s2=0

b=(a[a%2==0])

s1=sum(b)

s2=sum(a[a%2==1])

print ("sum os even no=",s1)

print ("sum os odd no=",s2)

OUTPUT:

14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy