Exp 7 - Shruti Anand
Exp 7 - Shruti Anand
Exp 7 - Shruti Anand
Venue : Online
Max. Marks
Particulars
Marks Obtained
Pre-lab 05
Program 10
Post-lab 05
Output Verification 15
Viva 05
Total 40
REPORT VERIFICATION
Signature :
7. Program to calculate students Grades using Dictionary
7.1 Aim
Write Python program to explore dictionary data type in python with the following task
1. Creating a dictionary which consists of the student name, assignment, Lab, test mark
2. Write a Function to calculates average marks and
3. Write a Function to calculates total mark for each student based on weightage of assignment,
test and lab mark
4. Write a Function to Calculate letter grade of each student
5. Write a Function to calculate the total average marks of the whole class
6. Call all the functions for set of students and print the results
1. Anaconda Navigator
2. Jupyter Notebook
2. Modify the value/Key value in the dictionary by adding two more states
and capitals.
3. How to delete a specific value in a dictionary?
4. Is a python dictionary modifiable? Write one example.
7.4(a) Algorithm
1. Create a dictionary with the key of Student name, assignments, test and lab mark.
3. Create a function “get_average” to find avg. marks of assignment, test and lab
Marks
6. Create a Function to calculate the total average marks of the whole class
7. Execute the program enter input and check the final result
Program:
# 1 .Creating a dictionary which consists of the student name, assignment, Lab, test marks
#s1 to s5 are dictionary of five students
s1 = { "name":"student 1",
"assignment" : [80, 50, 40, 20],
"test" : [75, 75],
"lab" : [78.20, 77.20]
}
s2 = { "name":"student 2",
"assignment" : [82, 56, 44, 30],
"test" : [80, 80],
"lab" : [67.90, 78.72]
}
s3 = { "name" : "student 3",
"assignment" : [77, 82, 23, 39],
"test" : [78, 77],
"lab" : [80, 80]
}
s4 = { "name" : "student 4",
"assignment" : [67, 55, 77, 21],
"test" : [40, 50],
"lab" : [69, 44.56]
}
s5 = { "name" : "student 5",
"assignment" : [29, 89, 60, 56],
"test" : [65, 56],
"lab" : [50, 40.6]
}
# 2.Function to calculates average marks
def get_average(marks):
total_sum = float(sum(marks))
return total_sum / len(marks)
# 3.Function to calculates total mark for each student based on weightage of assignment,test and
lab mark
def calculate_total_mark(students):
assignment = get_average(students["assignment"])
test = get_average(students["test"])
lab = get_average(students["lab"])
# Iterate through the students list and calculate their respective total marks and letter grade
for i in students :
print(i["name"])
print("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=")
print("Total mark of %s is : %s " %(i["name"],
calculate_total_mark(i)))
Output response:
student 1
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Average marks of student 1 is : 72.79
Letter Grade of student 1 is : C
student 2
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Average marks of student 2 is : 75.962
Letter Grade of student 2 is : C
Student 3
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Average marks of student 3 is : 75.775
Letter Grade of student 3 is : C
student 4
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Average marks of student 4 is : 48.356
Letter Grade of student 4 is : E
student 5
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Average marks of student 5 is : 57.26
Letter Grade of student 5 is : E
7.4 Observation
7.4. Post Lab Question
1. Follow the steps bellow: -Create a new dictionary called prices using {} .
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
Loop through each key in prices. For each key, print out the key along with its price and stock
information. Print the answer in the following format:
apple
price: 2
stock: 0
● Let's determine how much money you would make if you sold all of your food.
● Create a variable called total and set it to zero.
● Loop through the prices dictionaries. For each key in prices, multiply the number in
prices by the number in stock. Print that value into the console and then add it to total.
● Finally, outside your loop, print total.
Ans:
2. Write a program that accepts a sentence and calculate the number of letters and digits in the
given sentence
Suppose the following input is supplied to the program:
Scientific python! 2022
Then, the output should be:
LETTERS 16
DIGITS 4
Ans:
3. Write a python program using dictionary to create a small dictionary (min of five words) of
synonyms. the program should accept a word and generate synonyms for the same
7.5: Result
Creating a module in Python read data of the students into dictionary, find the average grades.