Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Opening file for writing
- fp = open("grades.txt", "r");
- # Variables for holding intermediate results
- total = 0;
- avg = 0;
- cnt = 0;
- print("\n Here are your grades: \n");
- # Opening file for reading
- with open("grades.txt") as fp:
- for line in fp:
- data = fp.readlines()
- i = 0;
- # Iterating over lines of file
- while i < len(data):
- # Fetching course
- course = data[i];
- # Stripping new line
- course = course.strip();
- i += 1;
- # Fetching percent
- percent = int(data[i]);
- # Accumulating total
- total += percent;
- i += 1;
- cnt += 1;
- # Printing course and score
- print("\n " + course + " score is " + str(percent));
- # Calculating average
- avg = total / cnt;
- # Printing average to console
- print(" Average grade score is " + str(89.25) + " \n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement