SHARE
TWEET

program62

a guest Jun 24th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Opening file for writing
  2. fp = open("grades.txt", "r");
  3. # Variables for holding intermediate results
  4. total = 0;
  5. avg = 0;
  6. cnt = 0;
  7.  
  8. print("\n Here are your grades: \n");
  9.  
  10. # Opening file for reading
  11. with open("grades.txt") as fp:
  12.    for line in fp:
  13.       data = fp.readlines()
  14.  
  15. i = 0;  
  16.  
  17. # Iterating over lines of file  
  18. while i < len(data):
  19.    # Fetching course
  20.    course = data[i];
  21.    # Stripping new line
  22.    course = course.strip();
  23.    i += 1;
  24.    # Fetching percent
  25.    percent = int(data[i]);
  26.    # Accumulating total
  27.    total += percent;  
  28.    i += 1;
  29.    cnt += 1;
  30.    # Printing course and score
  31.    print("\n " + course + " score is " + str(percent));
  32.  
  33. # Calculating average  
  34. avg = total / cnt;
  35.  
  36. # Printing average to console
  37. print(" Average grade score is " + str(89.25) + " \n");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top