Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WE CAN\'T USE IF STATEMENTS • For example, if statements. Write a batch-oriented

ID: 3595417 • Letter: W

Question

WE CAN'T USE IF STATEMENTS

• For example, if statements.

Write a batch-oriented python program that does the following:

Explains to the user what it will do

Prompts the user for an input .dat file

Reads the names and scores from the input file

Prints to the screen the student names, students scores and student grades (based on 0-59 F, 60-69 D, 70-79 C, 80-89 B, 90-100 A) in the format: " received a score of for a grade of " A sample file called scores.dat is available within Module 3.

Writes the names, scores and grades to a new file called grades.dat formatted the same as the original file but with the grades added to the end of each line.

Properly handles all files (opens, reads and closes)

Scores.dat text looks like:

Suzy Studious 99

Sara Supreme 87

Sammy Student 95

Stephen Slacker 72

Remember, you can’t use structures we haven’t discussed yet.

• For example, if statements.

WE CAN'T USE IF STATEMENTS

Explanation / Answer

print("this program will generate a file with grades using provided score file")

filename = input("Enter a .dat file: ")


grades = 'FEDCBA'
with open(filename) as fh, open('grades.dat', 'w') as fw:
for line in fh:
(name, studentType, score) = line.split()
score = int(score)
grade = ((score // 10) - 4) * (score // 50) * (100 // (score + 1)) + (score // 100) * 5
grade = grades[grade]
print(name, "received a score of ", score, " for a grade of ", grade)
fw.write(name + " " +str(score) + " " + grade + ' ')

# copyable code link: https://paste.ee/p/UTOa5

Sample output

this program will generate a file with grades using provided score file
Enter a .dat file: scores.dat
Suzy received a score of 99 for a grade of A
Sara received a score of 87 for a grade of B
Sammy received a score of 95 for a grade of A
Stephen received a score of 72 for a grade of C