Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The assignement:
Make a program that returns as output "Congratulations # for the excellent performance!" to all students (replacing the name "#" with the student's name) who have an average grade (of all their subjects) higher than the class average.

- It is necessary to ask the names of the students, the names of the subjects, the grades of the students in each of the subjects and the average of each student.

- Students must be displayed on the monitor, sorted by their average. The name and average of each student should appear. Must use the bubble sort function.

- Must display the name of the student (and respective average) of the student with the best average on the monitor.

- Must display the name of the student (and respective average) of the student with the lowest average on the monitor.

Note: The names of the subjects must be asked only once by the program- the subjects must be associated to each student.

--------

Hello, this is my assignement, I've been trying to make it in different ways for a couple of days and this has been my most sucessful try. As you can see, I've written that the class has 3 students but in reality it should have 30 (I did this for it to be quicker).
The program that I made is also very long and is quite different from what my professor wants. We just finished learning about append, functions and lsits.
If someone could show me how it's done, I'd appreciate it alot!
(Sorry if my english is bad.)

What I have tried:

Python
num_students = 3
num_subjects = 5

sum_class = 0
sum_student = 0

averages_students = [[]]
names = []
subjects = []

average_class = 0
name_disc_grades = [[]]

i = 0
j = 0
grade = 0

#obtain names of subjects
while i < num_subjects:
name_subject = input("Name of the subject: ")
if name_subject:
subjects.append(name_subject)
i = i + 1
name_subject = None

print("List of subjects: ")
print(subjects)

i = 0
#obtain names of students
while i < num_students:
name_student = input("Name of the student: ")

if name_student:
name_student = input("Name of the student: ")
if name_student
subjects.append(name_student)
i = i + 1
name_student = None

#clean variables, list and matrix
i = 0
j = 0
name_disc_grades.clear()
averages_students.clear()

#obtain grades of student per subject
for i in range(num_students):
while j < num_subjects:
#we know that we are going to iterate over 1 student and all subjects.
grade = eval(input("indicate the grade of student " + names[i] + " the subject " + subjects[j] + ": "))

names_disc_grades.append([str(names[i]), str(subjects[j]), float(grade)])
if grade:
sum_class = sum_class + int(grade)
sum_student = sum_student+ int(grade)
j = j + 1

print("----------------------------------------------------------------------")
averages_students.append([str(names[i]), float(sum_student / num_subjects)])
sum_student = 0
j = 0
i = i + 1

average_class = float(sum_class/num_subjects/num_students)
print("")
print("average of class is: ", average_class)
print("")
print("all averages of students: ")
print(averages_students)

#modificate the comparison to see average value and not the set [name,average]
def bubbleSort(theSeq):
n = len(theSeq)

for i in range(n - 1):
flag = 0
for j in range(n-1):

if theSeq[j][1] > theSeq[j + 1]
[1]:
tmp = theSeq[j]
theSeq[j] = theSeq[j + 1]
theSeq[j + 1] = tmp
flag = 1

if flag == 0:
breakpoint()
return theSeq

# sort list by grade [name,grade]
average_students = bubbleSort(averages_students)
print("")
print('averages sorted: ')
print(average_students)

# averages_students[-1] when using this negative number, it'll always fetch the last register on the list, we know that # is the biggest because the list is descending, it should always give the best average.
# the student with the biggest average
print("")
print("the student with the biggest/better average and:", averages_students[-1][0])
print(congratualations for the excelent performance!")
print("with the average of: ", averages_students[-1][-1])

# here the same, and always the first score of the list [name, average]
# the student with smallest average
print("")
print("students with average superior to the average of the class are: ")
i=0
#compare
for i in range(num_students):
if average_students[i][1] > average_class:
print('Congratulations'. names[i], "for your average of", average_students[i][1], "!")
print("----------------")

#extra - show all grades by student by subject.
print("")
print("All of the grades of each student by subject: ", names_disc_grades)
Posted
Updated 27-Nov-22 10:58am
v2

1 solution

I'm sure I've seen this question before a week or so ago ... Using Python language- how that gives the output "congraadulations" to every student with a higher average than the class average[^]. Perhaps you should get together with your class mate ...

It's pretty simple, but since it's your homework I'll give you no code.

Think about it: you need to congratulate each student that has a higher than average grade. So what is the first thing you need to know?

Obviously, it's the class average grade - because without that you can't check if they are above it.
So work that out first, then process each student in turn and check their grade against it.



If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900