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

First Year Lab Manual 24 - 25

The document is a first-year lab manual for Python programming, containing a comprehensive list of programming exercises categorized into two parts: Part-A and Part-B. Each exercise includes a description of the task, example code, and expected output. Additionally, it outlines the practical exam pattern with marks distribution for various components.

Uploaded by

Simran Shaikh
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 views28 pages

First Year Lab Manual 24 - 25

The document is a first-year lab manual for Python programming, containing a comprehensive list of programming exercises categorized into two parts: Part-A and Part-B. Each exercise includes a description of the task, example code, and expected output. Additionally, it outlines the practical exam pattern with marks distribution for various components.

Uploaded by

Simran Shaikh
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/ 28

FIRST YEAR

LAB MANUAL

PYTHON
PROGRAMMING

PREPARED BY

NARESH RAMANE AKASH HARAJI PRIYAVANDANA LOHAR


INDEX
SL NO. PROGRAM LIST
PART-A
1 Write a program to swap two numbers using a third variable.
2 Write a program to enter two integers and perform all arithmetic operations on
them.
3 Write a Python program to accept length and width of a rectangle and compute
its perimeter and area.
4 Write a Python program to calculate the amount payable if money has been lent
on simple interest. Principal or money lent = P, Rate of interest = R% per annum
and Time = T years. Then Simple Interest (SI) = (P x R x T)/ 100. Amount payable
= Principal + SI. P, R and T are given as input to the program
5 Write a Python program to find largest among three numbers.
6 Write a program that takes the name and age of the user as input and displays a
message whether the user is eligible to apply for a driving license or not. (the
eligible age is 18 years)
7 Write a program that prints minimum and maximum of five numbers entered by
the user.
8 Write a program to find the grade of a student when grades are allocated as given
in the table below.
Percentage of Marks Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program.
9 Write a function to print the table of a given number. The number has to be
entered by the user
10 Write a program to find the sum of digits of an integer number, input by the user.
11 Write a program to check whether an input number is a palindrome or not
12 Write a program to print the following patterns:
12345
1234
123
12
1
PART-B
13 Write a program that uses a user defined function that accepts name and gender
(as M for Male, F for Female) and prefixes Mr./Ms. based on the gender.
14 Write a program that has a user defined function to accept the coefficients of a
quadratic equation in variables and calculates its discriminant. For example : if
the coefficients are stored in the variables a, b, c then calculate discriminant as
b2-4ac. .Write the appropriate condition to check discriminant on positive, zero
and negative and output appropriate result.
15 Write a program that has a user defined function to accept 2 numbers as
parameters, if number 1 is less than number 2 then numbers are swapped and
returned, i.e., number 2 is returned in place of number1 and number 1 is
reformed in place of number 2, otherwise the same order is returned.
16 Write a program to input line(s) of text from the user until enter is pressed. Count
the total number of characters in the text (including white spaces), total number
of alphabets, total number of digits, total number of special symbols and total
number of words in the given text. (Assume that each word is separated by one
space).
17 Write a user defined function to convert a string with more than one word into
title case string where string is passed as parameter. (Title case means that the
first letter of each word is capitalized)
18 Write a function that takes a sentence as an input parameter where each word in
the sentence is separated by a space. The function should replace each blank with
a hyphen and then return the modified sentence.
19 Write a program to find the number of times an element occurs in the list
20 Write a function that returns the largest element of the list passed as parameter
21 Write a program to read a list of elements. Modify this list so that it does not
contain any duplicate elements, i.e., all elements occurring multiple times in the
list should appear only once
22 Write a program to read email IDs of n number of students and store them in a
tuple. Create two new tuples, one to store only the usernames from the email
IDs and second to store domain names from the email IDs. Print all three tuples
at the end of the program. [Hint: You may use the function split()]
23 Write a program to input names of n students and store them in a tuple. Also,
input a name from the user and find if this student is present in the tuple or not.
24 Write a Python program to create a dictionary from a string. Note: Track the count
of the letters from the string. Sample string : ‘2nd pu course’ Expected output : {‘
‘:2, ‘2’:1, ‘n’:1, ‘d’:1, ‘o’:1, ‘p’:1, ‘u’:2, ’c’:1, ‘s’:1, ‘r’:1, ‘e’:1}
OR
Create a dictionary with the roll number, name and marks of n students in a class
and display the names of students who have marks above 75
PRACTICAL EXAM PATTERN
Sl. No Program Marks

1 Writing 1 Program from PART-A 6 Marks

2 Writing 1 Program from PART-B 6 Marks

3 Execution of any one program of examiner’s choice 8 Marks

4 Practical record 6 Marks

5 Viva-voce (Four Questions related to the program written by the 4 Marks


student in Exam)
TOTAL MARKS 30 Marks
PART-A PROGRAMS
1.Write a program to swap two numbers using a third variable.
PROGRAM-

# swapping of two variables


x = int(input('Enter the first value' ))
y = int(input('Enter the second value'))
print("Values of variables before swapping")
print("Value of x:", x)
print("Value of y:", y)
# Swapping of two variables
# Using third variable
temp = x
x=y
y = temp
print("Values of variables after swapping")
print("Value of x:", x)
print("Value of y:", y)

OUTPUT-
Enter the first value 34
Enter the second value 65
Values of variables before swapping
Value of x: 34
Value of y: 65
Values of variables after swapping
Value of x: 65
Value of y: 34
2. Write a program to enter two integers and perform all arithmetic operations on
them.
PROGRAM-

#Program to input two numbers and performing all arithmetic operations


num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Printing the result for all arithmetic operations:- ")
print("Addition: ",num1+num2)
print("Subtraction: ",num1-num2)
print("Multiplication: ",num1*num2)
print("Division: ",num1/num2)
print("Modulus: ", num1%num2)

OUTPUT-
Enter first number: 34
Enter second number: 66
Printing the result for all arithmetic operations:-
Addition: 100
Subtraction: -32
Multiplication: 2244
Division: 0.5151515151515151
Modulus: 34

3. Write a Python program to accept length and width of a rectangle and compute
its perimeter and area.

PROGRAM-

#Program to input length and width of rectangle and compute its perimeter and area.

length = int(input("Enter length: "))


width = int(input("Enter width: "))
area = length * width
print(‘AREA=’, area)
perim = 2 * (length + width)
print(‘PERIMETER=’, perim)

OUTPUT-
Enter length: 4
Enter width: 5
AREA=20
PERIMETER=18

4. Write a Python program to calculate the amount payable if money has been lent on
simple interest. Principal or money lent = P, Rate of interest = R% per annum and
Time = T years. Then Simple Interest (SI) = (P x R x T)/ 100. Amount payable =
Principal + SI. P, R and T are given as input to the program

PROGRAM-
#Program to input principle , rate, time and compute simple interest

P = float(input("Enter principle amount: "))


R =float(input("Enter rate: "))
T = float(input("Enter time: "))
SI=(P*R*T)/100
print('PRINCIPLE AMOUNT=', P)
print('RATE OF INTEREST=', R)
print('TIME=', T)
print('SIMPLE INTEREST=', SI)
AMOUNT=P+SI
print('AMOUNT PAYABLE=', AMOUNT)

OUTPUT-
Enter principle amount: 10000.00
Enter rate: 2.5
Enter time:1.0
PRINCIPLE AMOUNT=10000.00
RATE OF INTEREST=2.5
TIME=1.0
SIMPLE INTEREST= 250.00
AMOUNT PAYABLE=10250.00

5. Write a Python program to find largest among three numbers.


PROGRAM-
a=int(input("enter first number:"))
b=int(input("enter second number:"))
c=int(input("enter third number:"))
if(a>b):
if(a>c):
print(a,"is the largest")
else:
print(c,"is the largest")
else:
if(b>c):
print(b,"is the largest")
else:
print(c,"is the largest")

OUPUT-
enter first number:12
enter second number:18
enter third number:11
18 is the largest

6. Write a program that takes the name and age of the user as input and displays a
message whether the user is eligible to apply for a driving license or not. (the eligible
age is 18 years).

PROGRAM-
input("enter name:")
x=int(input("enter age:"))

if(x>=18):
print(“eligible for license”)
else:
print(“ not eligible for license")
OUPUT-
enter name:naresh
enter age:23
23 eligible for license

enter name:aarya
enter age:4
4 not eligible for license

7. Write a program that prints minimum and maximum of five numbers entered by the
user.

PROGRAM-
minimum=0
maximum=0
for a in range(0,5):
x=int(input("enter the number:"))
if a==0:
minimum=maximum=x
if(x<minimum):
minimum=x
if(x>maximum):
maximum=x
print("the minimum number is",minimum)
print("the maximum number is",maximum)

OUPUT-
enter the number:10
enter the number:11
enter the number:5
enter the number:3
enter the number:2

the minimum number is 2


the maximum number is 11

8. Write a program to find the grade of a student when grades are allocated as given in the
table below. Percentage of Marks Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program.

PROGRAM-
sub1=int(input("enter marks of the first subject: "))
sub2=int(input("enter marks of the second subject: "))
sub3=int(input("enter marks of the third subject: "))
sub4=int(input("enter marks of the fourth subject: "))
sub5=int(input("enter marks of the fifth subject: "))
sub6=int(input("enter marks of the sixth subject: "))

total=(sub1+sub2+sub3+sub4+sub5+sub6)
print("TOTAL=",total)

perc=total/6
print("PERCENTAGE=",perc)

if(perc>=90):
print("Grade: A")
elif(perc>=80 and perc<90):
print("Grade: B")
elif(perc>=70 and perc<80):
print("Grade: C")
elif(perc>=60 and perc<70):
print("Grade: D")
else:
print("Grade: E")

OUPUT-
enter marks of the first subject: 45
enter marks of the second subject: 55
enter marks of the third subject: 65
enter marks of the fourth subject: 75
enter marks of the fifth subject: 85
enter marks of the sixth subject: 95
TOTAL= 420
PERCENTAGE= 70.0
Grade: C

9. Write a function to print the table of a given number. The number has to be entered by
the user.

PROGRAM-

n=int(input("enter number to print the tables:"))


for i in range(1,11):
print(n,"x",i,"=",n*i)

OUTPUT-

enter number to print the tables:4


4x1=4
4x2=8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40

10. Write a program to find the sum of digits of an integer number, input by the user.

PROGRAM-

num=input("enter number:")
sum=0

for i in num:
sum=sum+int(i)

print(sum)

OUTPUT-
enter number:123456
21

11. Write a program to check whether an input number is a palindrome or not.

PROGRAM-
n=int(input("enter number:"))
temp=n
rev=0
while(n>0):
digit=n%10
rev=rev*10+digit
n=n//10
if(temp==rev):
print("the number is a palindrome!")
else:
print("the number is not a palindrome!")

OUTPUT-
1.
enter number:1234
the number is not a palindrome!
2.
enter number:1221
the number is a palindrome!

12. Write a program to print the following patterns:


12345
1234
123
12
1

PROGRAM-
n=5
for i in range(n,0,-1):
for j in range(1,i+1):
print(j,end=" ")
print("\r")

OUTPUT-

12345
1234
123
12
1
PART-B PROGRAMS
13. Write a program that uses a user defined function that accepts name and gender (as M
for Male, F for Female) and prefixes Mr./Ms. based on the gender.
PROGRAM-
# defining a function which takes name and gender as input
def prefix(name,gender):
if(gender=='M' or gender=='m'):
print("Hello, Mr.",name)
elif(gender=='F' or gender=='f'):
print("Hello, Ms.",name)
else:
print("Please enter only M or F in gender")

#asking the user to enter the name


name=input("enetr your name:")

#asking the user to enter the gender a M/F


gender=input("enter your gender: M for Male, and F for female:")

#calling function
prefix(name,gender)

OUTPUT-
enetr your name:naresh
enter your gender: M for Male, and F for female: M

Hello, Mr. naresh

OUTPUT-
enetr your name:aarya
enter your gender: M for Male, and F for female: f
Hello, Ms. Aarya

OUTPUT-
enetr your name:xyz
enter your gender: M for Male, and F for female:b
Please enter only M or F in gender

14. Write a program that has a user defined function to accept the coefficients of a quadratic
equation in variables and calculates its discriminant. For example : if the coefficients are
stored in the variables a, b, c then calculate discriminant as b2-4ac . .Write the appropriate
condition to check discriminant on positive, zero and negative and output appropriate
result.

PROGRAM-

#python program to find roots of quadratic equation


import math

#function for finding roots

def equationroots(a,b,c):
#calculating discriminant using formula
disc=b*b-4*a*c
sqrt_val=math.sqrt(abs(disc))

#checking condition for discriminant

if disc>0:
print("real and different roots")
print((-b+sqrt_val)/(2*a))
print((-b-sqrt_val)/(2*a))
elif disc==0:
print("real and equal roots")
print(-b/(2*a))
print(-b/(2*a))
else:
print("complex roots")
print(-b/(2*a),”+I”,sqrt_val)
print(-b/(2*a),”-I”,sqrt_val)

a=int(input("enter first coefficient:"))


b=int(input("enter second coefficient:"))
c=int(input("enter third coefficient:"))

if a==0:
print("input correct coefficient for quadratic equation")
else:
equationroots(a,b,c)

OUTPUT-
enter first coefficient:1
enter second coefficient:2
enter third coefficient:1
real and equal roots
-1.0
-1.0
OUTPUT-
enter first coefficient:5
enter second coefficient:1
enter third coefficient:2
complex roots
-0.1 +i 6.244997998398398
-0.1 -i 6.244997998398398

OUTPUT-
enter first coefficient:1
enter second coefficient:5
enter third coefficient:2
real and different roots
-0.4384471871911697
-4.561552812808831

OUTPUT-

enter first coefficient:0


enter second coefficient:1
enter third coefficient:2
input correct coefficient for quadratic equation

15. Write a program that has a user defined function to accept 2 numbers as parameters, if
number 1 is less than number 2 then numbers are swapped and returned, i.e., number 2
is returned in place of number1 and number 1 is reformed in place of number 2, otherwise
the same order is returned.

PROGRAM-
#defining a function to swap the numbers
def swap(a,b):
if(a<b):
return b,a
else:
return a,b
#asking the user to provide two numbers
n1=int(input("enter number 1:"))
n2=int(input("enter number 2:"))
print("Before swapping numbers:")
print("Number 1:",n1)
print("Number 2:",n2)
print("After swapping numbers:")
n1,n2=swap(n1,n2)
print("Number 1:",n1)
print("Number 2:",n2)

OUTPUT-
enter number 1:100

enter number 2:200


Before swapping numbers:
Number 1: 100
Number 2: 200
After swapping numbers:
Number 1: 200
Number 2: 100

16. Write a program to input line(s) of text from the user until enter is pressed. Count the
total number of characters in the text (including white spaces),total number of
alphabets, total number of digits, total number of special symbols and total number of
words in the given text. (Assume that each word is separated by one space).

PROGRAM-
userInput = input("Write a sentence: ")
#Count the total number of characters in the text (including white spaces)which is the length
of string
totalChar = len(userInput)
print("Total Characters: ",totalChar)
#Count the total number of alphabets,digit and special characters by looping through each
character and incrementing the respective variable value
totalAlpha = totalDigit = totalSpecial = 0
for a in userInput:
if a.isalpha():
totalAlpha += 1
elif a.isdigit():
totalDigit += 1
else:
totalSpecial += 1
print("Total Alphabets: ",totalAlpha)
print("Total Digits: ",totalDigit)
print("Total Special Characters: ",totalSpecial)
#Count number of words (Assume that each word is separated by one space)
#Therefore, 1 space:2 words, 2 space:3 words and so on
totalSpace = 0
for b in userInput:
if b.isspace():
totalSpace += 1
print("Total Words in the Input :",(totalSpace + 1))

OUTPUT-
Write a sentence: HOW ARE YOU
Total Characters: 11
Total Alphabets: 9
Total Digits: 0
Total Special Characters: 2
Total Words in the Input : 3
OUTPUT-
Write a sentence: COMPUTER SCIENCE PUC-1
Total Characters: 22
Total Alphabets: 18
Total Digits: 1
Total Special Characters: 3
Total Words in the Input : 3

17. Write a user defined function to convert a string with more than one word into title
case string where string is passed as parameter. (Title case means that the first letter
of each word is capitalised)

PROGRAM
#Changing a string to title case using title() function
def convertToTitle(string):
titleString = string.title()
print('The input string in title case is:',titleString)
userInput = input("Write a sentence: ")
#Counting the number of space to get the number of words
totalSpace = 0
for b in userInput:
if b.isspace():
totalSpace += 1
#If the string is already in title case
if(userInput.istitle()):

print("The String is already in title case")


#If the string is not in title case and consists of more than one word
elif(totalSpace > 0):
convertToTitle(userInput)
#If the string is of one word only
else:
print("The String is of one word only")

OUTPUT-
Write a sentence: good evening!
The input string in title case is: Good Evening!

OUTPUT-
Write a sentence: Good Morning
The String is already in title case

OUTPUT-
Write a sentence: science
The String is of one word only

18. Write a function that takes a sentence as an input parameter where each word in the
sentence is separated by a space. The function should replace each blank with a hyphen
and then return the modified sentence.

PROGRAM-
#replaceChar function to replace space with hyphen

def replaceChar(string):

return string.replace(' ','-')

userInput = input("Enter a sentence: ")

#Calling the replaceChar function to replace space with hyphen

result = replaceChar(userInput)

#Printing the modified sentence

print("The new sentence is:",result)

OUTPUT:
Enter a sentence: WELCOME TO THE WORLD OF COMPUTERS

The new sentence is: WELCOME-TO-THE-WORLD-OF-COMPUTERS


19. Write a program to find the number of times an element occurs in the list.

PROGRAM-
#defining a list

list1 = [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
#printing the list for the user
print("The list is:",list1)
#asking the element to count
inp = int(input("Which element occurrence would you like to count? "))
#using the count function
count = list1.count(inp)
#printing the output
print("The count of element",inp,"in the list is:",count)

OUTPUT:
The list is: [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
which element occurrence would you like to count?
10 The count of element 10 in the list is: 2
OUTPUT:
The list is: [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
Which element occurrence would you like to count?
50 The count of element 50 in the list is: 3

20. Write a function that returns the largest element of the list passed as parameter.
Using max() function of the list.

PROGRAM-
#Using max() function to find largest number
def largestNum(list1):
l = max(list1)
return l
list1 = [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
#Using largestNum function to get the function
max_num = largestNum(list1)
#Printing all the elements for the list
print("The elements of the list",list1)
#Printing the largest num
print("\nThe largest number of the list:",max_num)

OUTPUT:
The elements of the list [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]

The largest number of the list: 60

21. Write a program to read a list of elements. Modify this list so that it does not contain
any duplicate elements, i.e., all elements occurring multiple times in the list should
appear only once.

PROGRAM-

#function to remove the duplicate elements


def removeDup(list1):
#Checking the length of list for 'for' loop
length = len(list1)
#Defining a new list for adding unique elements
newList = []
for a in range(length):
#Checking if an element is not in the new List
#This will reject duplicate values
if list1[a] not in newList:
newList.append(list1[a])
return newList
#Defining empty list
list1 = []
#Asking for number of elements to be added in the list
inp = int(input("How many elements do you want to add in the list? "))
#Taking the input from user
for i in range(inp):
a = int(input("Enter the elements: "))
list1.append(a)
#Printing the list
print("The list entered is:",list1)
#Printing the list without any duplicate elements
print("The list without any duplicate element is:",removeDup(list1))

OUTPUT-

How many elements do you want to add in the list? 8


Enter the elements: 1
Enter the elements: 2
Enter the elements: 1
Enter the elements: 3
Enter the elements: 4
Enter the elements: 3 E
nter the elements: 5
Enter the elements: 6
The list entered is: [1, 2, 1, 3, 4, 3, 5, 6]
The list without any duplicate element is: [1, 2, 3, 4, 5, 6]

22. Write a program to read email IDs of n number of students and store them in a tuple.
Create two new tuples, one to store only the usernames from the email IDs and second
to store domain names from the email IDs. Print all three tuples at the end of the
program. [Hint: You may use the function split()]
PROGRAM-
#Program to read email id of n number of students. Store these numbers in a tuple.
#Create two new tuples, one to store only the usernames from the email IDs and second
to store domain names from the email ids.

emails = tuple()
username = tuple()
domainname = tuple()
#Create empty tuple 'emails', 'username' and domain-name
n = int(input("How many email ids you want to enter?: "))
for i in range(0,n):
emid = input("> ")

#It will assign emailid entered by user to tuple 'emails'


emails = emails +(emid,)

#This will split the email id into two parts, username and domain and return a list
spl = emid.split("@")

#assigning returned list first part to username and second part to domain name
username = username + (spl[0],)
domainname = domainname + (spl[1],)

print("\nThe email ids in the tuple are:")


#Printing the list with the email ids
print(emails)

print("\nThe username in the email ids are:")


#Printing the list with the usernames only
print(username)

print("\nThe domain name in the email ids are:")


#Printing the list with the domain names only
print(domainname)

OUTPUT-
How many email ids you want to enter?: 3
> [email protected]
> [email protected]
> [email protected]

The email ids in the tuple are:


(' [email protected]', '[email protected]', '[email protected]')

The username in the email ids are:


(' abcde', 'test1', 'testing')

The domain name in the email ids are:


('gmail.com', 'meritnation.com', 'outlook.com')

23. Write a program to input names of n students and store them in a tuple. Also, input a
name from the user and find if this student is present in the tuple or not.

PROGRAM-
#Program to input names of n students and store them in a tuple.
#Input a name from the user and find if this student is present in the tuple or not.
#Using a built-in function

name = tuple()
#Create empty tuple 'name' to store the values
n = int(input("How many names do you want to enter?: "))
for i in range(0, n):
num = input("> ")
#it will assign name entered by user to tuple 'name'
name = name + (num,)

print("\nThe names entered in the tuple are:")


print(name)
search=input("\nEnter the name of the student you want to search? ")

#Using membership function to check if name is present or not


if search in name:
print("The name",search,"is present in the tuple")
else:
print("The name",search,"is not found in the tuple")

OUTPUT-
How many names do you want to enter?: 3
> naresh
> akash
> priya

The names entered in the tuple are:


('naresh', 'akash', 'priya')

Enter the name of the student you want to search? priya


The name priya is present in the tuple

OUTPUT-
How many names do you want to enter?: 3
> naresh
> akash
> priya
The names entered in the tuple are:
('naresh', 'akash', 'priya')
Enter the name of the student you want to search? vidhan
The name vidhan is not found in the tuple
24. Write a Python program to create a dictionary from a string. Note: Track the count of the
letters from the string. Sample string : ‘2nd pu course’ Expected output : {‘ ‘:2, ‘2’:1, ‘n’:1,
‘d’:1, ‘o’:1, ‘p’:1, ‘u’:2, ’c’:1, ‘s’:1, ‘r’:1, ‘e’:1}

OR
Create a dictionary with the roll number, name and marks of n students in a class and
display the names of students who have marks above 75

PROGRAM-
myStr=input("The input string is:")
myDict=dict()
for character in myStr:
if character in myDict:
myDict[character]+=1
else:
myDict[character]=1

print("The dictionary created from characters of the string is:")


print(myDict)

OUTPUT-
The input string is: "welcome to cs department"
The dictionary created from characters of the string is:
{'"': 2, 'w': 1, 'e': 4, 'l': 1, 'c': 2, 'o': 2, 'm': 2, ' ': 3, 't': 3, 's': 1, 'd': 1, 'p': 1, 'a': 1, 'r': 1, 'n': 1}

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

result={}

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)

# Display names of students who have got marks more than 75

for student in result:

if result[student][1] > 75:

print(result[student][0])

OUTPUT-
Enter number of students: 3
Enter Details of student No. 1
Roll No: 121
Name: amit
Marks: 67
Enter Details of student No. 2
Roll No: 122
Name: sumit
Marks: 78
Enter Details of student No. 3
Roll No: 123
Name: akshay
Marks: 90
{121: ['amit', 67], 122: ['sumit', 78], 123: ['akshay', 90]}
sumit

akshay

You might also like