forked from werhereitacademy/Python_Modul_Week_2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion_1.py
More file actions
70 lines (51 loc) · 2.09 KB
/
Question_1.py
File metadata and controls
70 lines (51 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
You need to write a Python program to process a student's grades. The program needs to perform the following functions:
Store information and notes for 10 students using a dictionary. Let each student have their name, surname and grades
(Midterm, Final and Oral grades). For example:
1-Calculate each student's GPA and add it to the dictionary.
2-Find the student with the highest GPA and print it on the screen.
3- Separate each student's name from their surname and store them in a separate tuple and add them to a list.
4-Sort the names in alphabetical order and print the sorted list on the screen.
5-Keep students with a GPA below 70 in a cluster (set).
"""
student={} # 10 Student information list.
i=0
while i < 2: #Let each student have their name, surname and grades (Midterm, Final and Oral grades).
i+=1
name = str(input("Enter your |Full name : "))
midterm = int(input("Enter your midterm : "))
final = int(input("Enter your final: "))
oral = int(input("Enter your oral : "))
#1-Calculate each student's GPA and add it to the dictionary.
student[i] = {
"name" : name ,
"grades":[midterm,final, oral],
"gpa" : ((midterm + final + oral)//3) # "i" is een uniek number.
}
else :
print(student)
#2-Find the student with the highest GPA and print it on the screen.
gpa_list = []
names_list = []
for i in range(1,3):
gpa_list.append(student[i]["gpa"])
#It is for test , this mirror de data of k
#k =student[i]["gpa"]
#print(k)
na_me = student[i]["name"]
names_list.append(na_me)
print(gpa_list)
print(max(gpa_list))
#4-Sort the names in alphabetical order and print the sorted list on the screen.
names_list.sort(key = str.lower)
print(names_list)
#3- Separate each student's name from their surname and store them in
# a separate tuple and add them to a list.
name_sepr= "-".join(names_list)
print(name_sepr)
#5-Keep students with a GPA below 70 in a cluster (set).
s = set()
for grad in gpa_list :
if grad <= 70 :
s.add(grad)
print(s)