Exp 7 - Shruti Anand

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

SRM Institute of Science and Technology

College of Engineering and Technology

Department of Electronics and Communication Engineering

18ECE201J Python and Scientific Python

Fifth Semester, 2021-22 (Odd semester)

Name : Shruti Anand

Register No. : RA1911004010453

Venue : Online

Title of Experiment : Program to calculate students Grades using Dictionary

Date of Conduction : 30/08/2021

Date of Submission : 05/09/2021

Max. Marks
Particulars
Marks Obtained

Pre-lab 05

Program 10

Post-lab 05

Output Verification 15

Viva 05

Total 40

REPORT VERIFICATION

Staff Name : Mr.P.Vijayakumar

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

7.2 Software Used

1. Anaconda Navigator
2. Jupyter Notebook

7.3 Pre=Lab Questions


1. Create a dictionary for five states and capital. Print the same.

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.

2. Create database for five students using step1.

3. Create a function “get_average” to find avg. marks of assignment, test and lab
Marks

4. Create a function “calculate_total_mark” to find total marks based on weightage


of assignment, test and lab marks

5. Create a function assign_letter_grade to allocate grade based on the specification

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

Formula 1: calculate Grade based on total mark


score >= 90 : "A"
score >= 80 : "B"
score >= 70 : "C"
score >= 60 : "D"
for other : ”E”

Formula 2: calculate total marks based on weightage of each component


# Return the total marks based on weightage supplied
# 10 % from assignments
# 70 % from test
# 20 % from lab-works

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

# Return the total marks based on weightage supplied


# 10 % from assignments
# 70 % from test
# 20 % from lab-works
return (0.1 * assignment + 0.7 * test + 0.2 * lab)

# Grade will be calculated according to


# 1. score >= 90 : "A"
# 2. score >= 80 : "B"
# 3. score >= 70 : "C"
# 4. score >= 60 : "D"

# 4. Calculate letter grade of each student


def assign_letter_grade(score):
if score >= 90: return "A"
elif score >= 80: return "B"
elif score >= 70: return "C"
elif score >= 60: return "D"
else : return "E"

# Function to calculate the total average marks of the whole class


def class_average_is(student_list):
result_list = []
for student in student_list:
stud_avg = calculate_total_mark(student)
result_list.append(stud_avg)
return get_average(result_list)

# Student list consisting the


# dictionary of all students
students = [s1,s2,s3,s4,s5]

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

print("Letter Grade of %s is : %s" %(i["name"],


assign_letter_grade(calculate_total_mark(i))))
print()

# 5..Calculate the average of whole class


class_av = class_average_is(students)

print( "Class Average is %s" %(class_av))


print("Letter Grade of the class is %s "
%(assign_letter_grade(class_av)))

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

Class Average is 72.79


Letter Grade of the class is C

7.4 Observation
7.4. Post Lab Question

1. Follow the steps bellow: -Create a new dictionary called prices using {} .

Put these values in your prices dictionary:

"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

Hint : use isdigit(), isalpha() function

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

Hint: same key with different value


Ans:

7.5: Result
Creating a module in Python read data of the students into dictionary, find the average grades.

You might also like