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

FINAL 11 PRAC - Python

The document contains several programming exercises demonstrating basic Python functionalities. Exercises include counting character occurrences in a string, finding the third largest and smallest numbers in a list, creating and manipulating a dictionary of states and capitals, and determining the highest and lowest values in a dictionary. Each exercise includes an aim, methods used, coding examples, and expected outputs.

Uploaded by

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

FINAL 11 PRAC - Python

The document contains several programming exercises demonstrating basic Python functionalities. Exercises include counting character occurrences in a string, finding the third largest and smallest numbers in a list, creating and manipulating a dictionary of states and capitals, and determining the highest and lowest values in a dictionary. Each exercise includes an aim, methods used, coding examples, and expected outputs.

Uploaded by

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

EX:9

AIM :
To print the number of occurrences of a given alphabet in a given string.

METHODS:
input()
print()
lower()
range()
len()

CODING :
string = input("Enter any String : ")
char = input("\nEnter any character from the above string : ")
count = 0
ls=string.lower()
for i in range(len(ls)):
if(ls[i]==char):
count = count + 1
print("\nThe total number of times ", char, " has Occurred = " , count)

OUTPUT
Enter any String : HAVE A GREAT DAY

Enter any character from the above string : a

The total number of times a has Occurred = 4

EX:11
AIM :
To find the third largest and third smallest number in a list.

METHODS:
int()
input()
range()
append()
print()
sorted()

CODING :
lst = [ ]
num = int(input("How many numbers : "))
for n in range(num):
val = int(input("Enter value : "))
lst.append(val)
sort=sorted(lst)
print("\nSorted List = ", sort)
l=sorted(lst)[-3]
print("\nThird largest number in the list = ",l)
s=sorted(lst)[2]

OUTPUT
How many numbers : 6
Enter value : 65
Enter value : 45
Enter value : 89
Enter value : 12
Enter value : 76
Enter value : 98

Sorted List = [12, 45, 65, 76, 89, 98]

Third largest number in the list = 76

Third smallest number in the list = 65

EX:12
AIM :
To create a dictionary and store names of states, their capitals.

METHODS:
print()
get()
keys()
values()
items()
len()
del()

CODING :
stcap={'Tamilnadu':'Chennai', 'Bihar':'Patna', 'Rajasthan':'Jaipur',
'Manipur':'Imphal', 'Assam':'Dispur', 'Gujarat':'Gandhinagar',
'Maharashtra':'Mumbai'}
print(stcap.get("Bihar"))
print(stcap.keys())
print(stcap.values())
print(stcap.items())
print(len(stcap))
print("Maharashtra" in stcap)
del stcap["Assam"]
print(stcap)

OUTPUT
Patna
dict_keys(['Tamilnadu', 'Bihar', 'Rajasthan', 'Manipur', 'Assam', 'Gujarat',
'Maharashtra'])
dict_values(['Chennai', 'Patna', 'Jaipur', 'Imphal', 'Dispur', 'Gandhinagar',
'Mumbai'])
dict_items([('Tamilnadu', 'Chennai'), ('Bihar', 'Patna'), ('Rajasthan', 'Jaipur'),
('Manipur', 'Imphal'), ('Assam', 'Dispur'), ('Gujarat', 'Gandhinagar'),
('Maharashtra', 'Mumbai')])
7
True
{'Tamilnadu': 'Chennai', 'Bihar': 'Patna', 'Rajasthan': 'Jaipur', 'Manipur': 'Imphal',
'Gujarat': 'Gandhinagar', 'Maharashtra': 'Mumbai'}

EX:13
AIM :
To print the highest and lowest values in the dictionary.

METHODS:
int()
input()
range()
append()
print()
max()
min()

CODING :
dic={}
l=[]
n=int(input("Number of Values:"))
for i in range(n):
val = int(input("Enter value : "))
l.append(val)
dic['value']=l
print("\n Dictionary Values")
print(dic)
print("\nHighest Value in the dictionary")
print(max(dic['value']))
print("\nLowest Value in the dictionary")
print(min(dic['value']))

OUTPUT
Number of Values:5
Enter value : 72
Enter value : -4
Enter value : 55
Enter value : 12
Enter value : 9

Dictionary Values
{'value': [72, -4, 55, 12, 9]}

Highest Value in the dictionary


72

Lowest Value in the dictionary


-4

You might also like