Question

Python 3.7.2 (Please comment on code and post screenshot of your source code. Thanks)

Part 1 You just finished administering the final exam for all of the students in the Introduction to Computer Programming cl

class1:

N00000001,A,A,D,D,C, D,D,A,,C,D,B,C,, B,C,B,D,A,C,,A,,C,D N00000002,,A,,D,,B,D,A,C,C,D, ,A,A,A, C,B,D,C,C,A,A, B,,D N00000003

Part 1 You just finished administering the final exam for all of the students in the "Introduction to Computer Programming classes this semester. The exam was a 25 question multiple choice exam, and it is your job to grade the exams. You have all of the scores stored in a series of text files (click here to download these files). To begin, download the data files and store them in a folder on your computer. Then create a new Python program inside of this folder called "YourName Assignment09 py Next, write a program that lets the user type in the name of a file. Attempt to open the supplied file for read access. If the file exists you can print out a confirmation message. If the file doesn't exist you should tell the user that the file cannot be found. Hint: use a trylexcept block to do this (don't just use a series of "if" statements- we want this program to be as "generic" as possible) Here's a sample running of the program: Enter a class file to grade (i.e. class1 for class1.txt): foobar File cannot be found. Enter a class file to grade (i.e. class1 for class1.txt): class1 Successfully opened class1.txt
N00000001,A,A,D,D,C, D,D,A,,C,D,B,C,, B,C,B,D,A,C,,A,,C,D N00000002,,A,,D,,B,D,A,C,C,D, ,A,A,A, C,B,D,C,C,A,A, B,,D N00000003,B,A, , D , C , B , D , A , C , C , , B,A,B,A,C,B,D,A,,A, , B,D,D N00000004,B,B,D, ,,B,D,A,C,C,D,B,A,B,A,C,B,D, , C,A,D,B,C,D N00000005,B,A, ,D, ,B,D,A,C, C, D,B,A, B,A,C,B,D,D, C,A,A,,D,D N00000006 , B , A , D , A , C , B , D , A , C , C , C , В , A , D , A , C, , C,A,C,A,C,B,D,A N00000007 , B , A, D, D, C, B, D, A, C, , D, B, A, B, A, C,B,D, , C,A,A,B,D, N00000008 , Α, A, D, D , C, , D, A, C,C,B,C,A,B,A,A,B,D,A,C,A, , B,B,D N00000009 , B ,A,,D,C,B,D,A,C,A,D,B,A,B,A,A,B,D,A,C,A,A,B,D,D N00000010,,A, D,B,C,B,D,A,C,C,D,B, A, B,A, C,B,D,A,D, ,,B,D,B N00000011,B,A,D, ,C,B,D,A, C,D,D,B,A, B,A,C, B,D,A,C,A, B,B,D,D N00000012,B, , D , D , C , В , D , A , C , C , D , В , А , В , A , A , В , D , A ,,A,A,A, , С N00000013,,A, D, ,B,B, ,A,C,A,D,B,A,B,D,C,B,D,A, C,A,A, B,D,D N00000014,B,B,D,D,C,B, , D , C , C , D , B , A , B , A , C ,,D,A,C,A,A,,D,D N00000015,A,C, C,D,C,B, ,A, C,C,D,B, A, B,A, C,B,D,A,C,A,B, ,D,D N00000016,B,A, C,D, ,B,D,A, C,C,D,B,A, B,A,C, B,D,A,C,A,A, B,D,D N00000017,B,A,D,D,C,B,C,A,D,C,D,A,A,D,A,C,B,D,D,B,,A,B,D,D NO0000018 , B , A, D, A , C , B, D, A , C , C , D, B, A, B,, , B,D,A,B,A,A,B,,D N00000O19 , В , A , D, D , C , B , D , C , C , C , , B, , B,D,C,B,D,A,,A,A,B,D,D N00000020,B, , D, D, C, B, D, A , C , B , ,,A,C,A,D,B,D,B,C,A,A,B,D,D
0 0
Add a comment Improve this question Transcribed image text
Answer #1

while True:
  

    try:
        filename = input("Enter a class to grade (i.e. class1 for class1.txt): ")
        filenametxt = filename + ".txt"
        f = open(filenametxt,"r")
        #file=f.read()
          

    except:
        print("File cannot be found.")
        print()
          
    else:
        print("Successfully opened ", filenametxt,sep='')
        print()
        break

file = f.read()

splitdata = file.split("\n")
#print(splitdata)

#for line in splitdata:

#    splitline = line.split(",")
  
print("**** ANALYZING ****")
print()
#count = 0
#N = 0
#invalid=0
answerkey = "B,A,D,D,C,B,D,A,C,C,D,B,A,B,A,C,B,D,A,C,A,A,B,D,D"
answerkey = answerkey.split(",")

invalid = 0
good = 0
grades = [ ]
valid_lines = []
final = []
for line in splitdata:
  
    splitline = line.split(",")
  
    count = 0
    N = 0
  
    invalid_line = 0
  
    for each in splitline:
#       good +=1
        #print(each)
        if count == 0:
            if each[0] != "N" or len(each) != 9 or each[1:].isnumeric() == False:
                print("Invalid line of data: N# is invalid")
                print(splitline)
                print()
                invalid += 1
                invalid_line += 1
            #continue
             
        count+=1


     
    if count != 26:
        print("Invalid line of data: does not contain exactly 26 values:")
        print(splitline)
        print()
        invalid += 1
        invalid_line += 1

    if invalid_line == 0:
        valid_lines.append(splitline)
        good += 1
        final.append(splitline[0])

      

  
if invalid == 0:
    #if good == len(splitline) and N == 1
    print("No errors found!")
    print()

print("**** REPORT ****")
print()
print("Total valid lines of data:",good)
print("Total invalid lines of data:",invalid)
print()

for splitline in valid_lines:
    correct = 0
    for i in range(len(splitline)-1):
        if splitline[i+1] == answerkey[i]:
            correct +=4
        elif splitline[i+1] == "":
            correct += 0
        elif splitline[i+1] != answerkey[i]:
            correct -= 1
    grades.append(correct)

grades2 = []
for grade in grades:
    grades2.append(grade)
grades2.sort()


sum_of_grades = sum(grades)
avg = (sum_of_grades / len(grades))
print("Mean (average) score:",format(avg,".2f"))
print("Highest score:",max(grades))
print("Lowest score:",min(grades))
print("Range of scores:", (max(grades) - min(grades)))

if len(grades) % 2 != 0:
    grades2.sort()
    print("Median score:",grades2[int(len(grades)//2+1)])
else:
    grades2.sort()
    median = (grades2[int(len(grades)/2-1)] + grades2[int(len(grades)/2)])/2
    print("Median score:", median)

unique=[]
seen=[]

for i in range(len(grades)):
    if grades[i] not in unique:
        unique.append(grades[i])
        seen.append(1)
    else:
        position = unique.index(grades[i])
        seen[position] += 1
    
mode = max(seen)
loc = seen.index(mode)
mode_list=[ ]

for i in range(len(seen)):
    if seen[i] == mode:
        mode_list += [unique[i]]
      


print("Mode score(s): ",end="")
for item in mode_list:
    print(item,"",end="")


final_grades = filename + "_grades.txt"
grades_file = open(final_grades,'w')
for i in range(len(final)):
    forfile = (final[i] + ','+ str(grades[i])+'\n')
    grades_file.write(forfile)
  
grades_file.close()

print()
curveq = input("Would you like to apply a curve to the scores? (y)es or (n)o?: ")
if curveq == "y":
    newavg = float(input("Enter desired mean score: "))
  
    adding = newavg - avg
  
    curved_grades = []
    for i in range(len(grades)):
        new_score = grades[i] + adding
        new_score = format(new_score,'.2f')
        curved_grades.append(new_score)
      
    curved_file = filename + "_grades_with_curve.txt"
    curved_grade = open(curved_file,'w')
    for i in range(len(final)):
        forcurvedfile = (final[i] + ',' + str(grades[i]) + ',' + str(curved_grades[i]) + '\n')
        curved_grade.write(forcurvedfile)
    curved_grade.close()
    print("Done! A new grade file has been written (",curved_file,")",sep='')


  

Add a comment
Know the answer?
Add Answer to:
Python 3.7.2 (Please comment on code and post screenshot of your source code. Thanks) class1: Part 1 You just finished administering the final exam for all of the students in the "Introduction t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • I need this in C++. This is all one question. Introduction Your eighth assignment will consist...

    I need this in C++. This is all one question. Introduction Your eighth assignment will consist of two programs, which will involve the use of simple classes. The source code for these problems should be submitted using the naming conventions we specified in class. Please note that your computer programs should comply with the commenting and formatting rules as described in class. For example, there should be a header for the whole program that gives the author's name, class name,...

  • Can you comment notes along with the code so I can follow along and understand what is being written?? Thanks in advance...

    Can you comment notes along with the code so I can follow along and understand what is being written?? Thanks in advance! Let's say we're in a directory and we want to rename every file ending in·c, to end in .C (i.e., capitalize the c'). Here's one way to do it: $ for i in *. c; b-basename "$1" .c'; mv "8b.c" do "8b.C". done Things get more complicated if you want more complex renaming. Say for example you just...

  • Principles of Computer Science

    Question First, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information, and all of these should be defined as Private: A. Title of the student (eg Mr, Miss, Ms, Mrs etc) B. A first name (given name) C. A last name (family name/surname) D. Student number (ID) – an integer number (of type long) E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class from...

  • Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your la...

    help with cse problem Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your lab session. Two people should work at one computer. Occasionally switch the person who is typing. Talk to each other about what you are doing and why so that both of you understand each step Part A: Class Date . Download the files for this laboratory exercise, then run the Python shell and enter the following commands: >>>import date >>help(...

  • please help!! the first photo is to answeer the 4 questions! i really just need help...

    please help!! the first photo is to answeer the 4 questions! i really just need help on question 11 and 12 QUESTION 9 Instructions A link to the data marathon is included in this section. You will use JMP to answer questions 9. 13. Each question includes the steps needed in JMP. In the following paragraph, you will find the steps to save graphs that you will need. marathon.txt Before loading the file into JMP, you will need to do...

  • Use of search structures! how can i make this program in python? Learning Objectives: You should...

    Use of search structures! how can i make this program in python? Learning Objectives: You should consider and program an example of using search structures where you will evaluate search trees against hash tables. Given the three text files under containing the following: - A list of students (classes Student in the distributed code) - A list of marks obtained by the students (classes Exam results in the distributed code) - A list of topics (classes Subject in the distributed...

  • just the extra credit part please Your customer needs an automated system to patrol the highways....

    just the extra credit part please Your customer needs an automated system to patrol the highways. The job of the system is to collect the following information on vehicles traveling down a certain stretch of highway: license plate number, current speed, and speed limit. A program is required to determine if a speeding ticket is needed for each set of data. Ticket will only be issued when number of miles per hours (mph) over the speed limit is at least...

  • in Python Project 5: Payroll (Part 1) CS 1410 Background In this project you will implement...

    in Python Project 5: Payroll (Part 1) CS 1410 Background In this project you will implement a simple payroll system. For the first part of the assignment, you will submit a UML class diagram. The hypothetical company we are considering has 3 classifications of employees: 1. Hourly 2. Salaried 3. Commissioned There are 24 pay periods per year; 1/24th of a salary is paid each pay period to employees who receive a salary. We won't worry about taxes and other...

  • 1 Overview The goal of this assignment is to help you understand caches better. You are...

    1 Overview The goal of this assignment is to help you understand caches better. You are required to write a cache simulator using the C programming language. The programs have to run on iLab machines. We are providing real program memory traces as input to your cache simulator. The format and structure of the memory traces are described below. We will not give you improperly formatted files. You can assume all your input files will be in proper format as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT