Question: In this assignment you have to write a program that displays administrative information about students in the course Programming for Artists. Data about those students

In this assignment you have to write a program that displays administrative information about students in the course Programming for Artists. Data about those students is once again stored in a file.
This is an example of such a file:
Piet van Gogh___567456
5=20=22=10=2=0=0=1=0=1;Vincent Appel,Johannes Mondriaan
Karel van Rijn___7866
2=30=15=8=4=3=2=0=0=0;
Herman Vermeer_4424566
9=10=10=5=1=1=0=0=0=1;Johannes Brood
Johannes Brood__1
12=22=12=0=2=0=0=0=1=0;Herman Vermeer
As you can see, this file contains two different types of lines. The first type of line is similar to the types of line that was used in the Geography Grades assignment. It contains the grades of a student, and has the following structure:
_
You have to calculate the final grade of the student. Similar to the Geography Grades assignment, all grades have the same weight. There is however a small change in the way that the final grade is determined:
If the average grade is >=5.5 and <6, the final grade will be noted as "6-".
In all other cases, the final grade will be the average grade, rounded to the nearest half.
The second type of line contains information about which students handed in programs that are similar to the student of the previous line. It has the following structure:
<10 numbers separated by equals signs>;
The first 10 numbers are the similarity scores. These scores represent the number of programs matching a certain percentage of the current program in steps of 10%. This means the first numbers indicates the matches from 1%-10% and the last number indicates the matches from 91%-100%.
Since this is not easy to read, you have to convert these numbers to a graph according to these rules:
If there are 0 matches, display an underscore:_
If there are less than 20 matches, display a minus sign:-
If there are 20 or more matches, display a caret:^
The names of the students after the semicolon are the names of the students with matches in the final 3 categories. The names of these students should be printed under the graph. If there are no matches, the program should print"No matches found".
The output for the file shown above should be as follows:
Piet van Gogh has an average of 6-
-^^--__-_-
Vincent Appel
Johannes Mondriaan
Karel van Rijn has an average of 7
-^-----___
No matches found
Herman Vermeer has an average of 4.5
------___-
Johannes Brood
Johannes Brood has an average of 1
-^-_-___-_
Herman Vermeer
this is my code but i dont understand whats wrond/missing
def sum_grades(grades):
result =0.0
for grade in grades:
result += float(grade)
return result
def calculate_final_grade(grades, sum_grades):
if sum_grades ==0:
return 0.0
average_grade = sum_grades / len(grades)
if 5.5<= average_grade <6.0:
final_grade =5.75
else:
final_grade = int(float(average_grade *2)+0.5)/2
return final_grade
def process_line_grades(line):
parts = line.split("_")
name = parts[0]
grades = parts[1].split().strip("_")
sumGrades = sum_grades(grades)
final_grade = calculate_final_grade(grades, sumGrades)
return name, final_grade
def process_line_similarity(line):
parts = line.split(";")
similarity_scores = parts[0].split("=")
matches = parts[1].split(",")
return similarity_scores, matches
graph =("")
for score in similarity_scores:
score = int(score)
if score ==0:
graph +="_"
elif score <20:
graph +="-"
else:
graph +="^"
return graph
file_name = input("Enter a file name: ")
file = open(file_name).read()
lines = file.splitlines()
i =0
while i < len(lines):
line = lines[i]
if "_" in line:# if so it's a grades line
name, final_grade = process_line_grades(line)
if final_grade ==5.75:
final_grade_string ="6-"
else:
final_grade_string ="%.1f"% final_grade
print ("%s has an average grade of %s"%(name, final_grade))
if i +1< len(lines) and "=" in lines[i +1]:
i +=1
graph, matches = process_line_similarity(lines[i])
print("graph")
if matches:
print(""+"
".join(matches))
else:
print(" No matches found")
i +=1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!