-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmaintest.py
More file actions
59 lines (40 loc) · 1.57 KB
/
Copy pathmaintest.py
File metadata and controls
59 lines (40 loc) · 1.57 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
def main():
num_students = get_int_input("Enter the number of students: ",1)
num_subjects = get_int_input("Enter the number of subjects: ",2)
student_data = [["" for j in range(num_subjects + 1)] for i in range(num_students)]
for i in range(num_students):
print(f"Enter data for student {i + 1}:")
student_data[i][0] = get_input("Name of student: ")
for j in range(1, num_subjects + 1):
marks = get_int_input(f"Enter marks for subject {j}: ", 0, 100)
student_data[i][j] = str(marks)
rank = get_int_input("Enter the rank to find: ", 1, num_students)
for i in range(1, num_subjects + 1):
print(f"Subject {i}:")
sorted_data = sort_data(student_data, i)
if rank <= num_students:
print(f"{rank} rank: {sorted_data[rank - 1][0]}")
else:
print("Invalid rank.")
def get_input(prompt):
while True:
value = input(prompt)
if value:
return value
print("Please enter a value.")
def get_int_input(prompt, min_value=None, max_value=None):
while True:
value = input(prompt)
if value:
try:
value = int(value)
if min_value is not None and value < min_value:
raise ValueError()
if max_value is not None and value > max_value:
raise ValueError()
return value
except ValueError:
pass
print("Please enter a valid integer value.")
if __name__ == "__main__":
main()