(a) Write a Python program to accept names of students and their list of mario
three subjects as input and append them in a dictionary with name being the key
and list of marks being the value. Print the dictionary. For example, the output
dictionary may look like
Aman': 110,40,50), 'Akash': 170,80,9011
Also, print the sum of marks scored by each student
For example,
Aman: 100
Alash 240
(b)Explain the difference between Candidate key. Primary key and Alternately
through an example table
Answers
Answer:
name = input("enter your name:")
sub1 = input("marks of the first subject:")
sub2 = input("marks of the second subject:")
sub3 = input ("marks of the third subject:")
total = sub1 + sub2 + sub3
dict = { name: [f"{sub1}", f"{sub2}", f"{sub3}"] }
print(dict)
print(f"\n Total score of {name}: {total}"
Explanation:
this program can only be used to append one name at a time. if you wanna know how to add multiple names and data at the same time just tell me
(a)
n = int(input("Enter the number of students: "))
print()
stud_dict = dict()
for i in range(n):
w = input("Enter the name of the student: ")
x = float(input("Enter the marks of Subject 1: "))
y = float(input("Enter the marks of Subject 2: "))
z = float(input("Enter the marks of Subject 3: "))
stud_dict[w] = [x, y, z]
print()
print()
print(stud_dict)
print()
for i in stud_dict:
tm = 0
for j in stud_dict[i]:
tm = tm + j
print("The total marks secured by", i, "is", str(tm) + ".")
(b)
Candidate Key
A candidate key is an attribute that is capable of being a Primary Key.
Alternate Key
An alternate key is a candidate key that is not the Primary Key in a table/showing capability of being a Primary Key.
Primary Key
A Primary Key is a set of values that are uniquely identified/where values cannot be duplicated.
From the table attached below, we can agree that ItemNo and ItemName are Candidate Keys, as they show the capability of being Primary Keys. The Alternate Key would be ItemName as it could still be duplicated, and the Primary Key would be ItemNo, since no two items can have the same ItemNo.