Question

For each problem, you must: Write a Python program Test, debug, and execute the Python program...

  • For each problem, you must:
    1. Write a Python program
    2. Test, debug, and execute the Python program
    3. Save your program in a .py file and submit your commented code to your Student Page.
    4. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method.
  1. (25 pts.) Write a program that reads in a file that contains lines consisting of a student name and five numbers representing the scores marks in English, History, Math, Biology, and Spanish. For example, the file might consist of the following lines:

    Baker 91 87 71 62 79
    Jones 55 88 77 99 56
    Smith 62 56 82 77 92

    Use five dictionaries (one for each subject) to store the names and numbers. Once all the names and numbers have been stored, add a function that utilizes the newly created dictionaries to print out the names of all students with failing grades (less than 60) along with the subjects they failed. Note: The data file that will be used to test the programs will only contain last names and all data items will be separated by a space.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//code screenshot

//code

#this function takes all the dictionaries and prints the failures
def printFailures(english,history,math,biology,spanish):
#loops through the five dictionaries and prints the student who has marks less than 60
for d in english:
if(english[d]<60):
print(d,' ',english[d],' English')
for d in history:
if(history[d]<60):
print(d,' ',history[d],' History')
for d in math:
if(math[d]<60):
print(d,' ',math[d],' Math')
for d in biology:
if(biology[d]<60):
print(d,' ',biology[d],' Biology')
for d in spanish:
if(spanish[d]<60):
print(d,' ',spanish[d],' Spanish')

#declared five dictionaries.
english={}
history={}
math={}
biology={}
spanish={}
#opens the file and generates the dictionaries
with open("marks.txt","r") as file:
lines=file.readlines() #reads all the lines from the file
for line in lines: #taking each line from lines
arr = line.split(' ') #splits the lien and populates the dictionaries
english[arr[0]]=int(arr[1])
history[arr[0]]=int(arr[2])
math[arr[0]]=int(arr[3])
biology[arr[0]]=int(arr[4])
spanish[arr[0]]=int(arr[5])

#calls the printFailures function
printFailures(english,history,math,biology,spanish)
  
  
//marks.txt file screenshot

//output screnshot

//any query, post in the comment section

Add a comment
Answer #2

class Grades:
   """
This is a class for reading grades from a file.
  
Attributes:
english (dictionay): carries name along with marks (name:marks)
history (dictionay): carries name along with marks (name:marks)
math (dictionay): carries name along with marks (name:marks)
biology (dictionay): carries name along with marks (name:marks)
spanish (dictionay): carries name along with marks (name:marks)
"""
   def __init__(self):
       self.english={}
       self.history={}
       self.math={}
       self.biology={}
       self.spanish={}

   def readfile(self):
       """
   reades from the "gradefile.txt" and enter marks into the respective subject dictionary
  
   """
       file=open("gradefile.txt","r")
       for i in file:
           line=i.split()
           self.english[line[0]]=int(line[1])
           self.history[line[0]]=int(line[2])
           self.math[line[0]]=int(line[3])
           self.biology[line[0]]=int(line[4])
           self.spanish[line[0]]=int(line[5])

   def englishFailed(self):
       """
   iterates over every key/value pair of the "english" dictionary and prints failed student
  
   """
       for student in self.english:
           if self.english[student]<60:
               print("english "+student)

   def historyFailed(self):
       """
   iterates over every key/value pair of the "history" dictionary and prints failed student
  
   """
       for student in self.history:
           if self.history[student]<60:
               print("history "+student)


   def mathFailed(self):
       """
   iterates over every key/value pair of the "math" dictionary and prints failed student
  
   """
       for student in self.math:
           if self.math[student]<60:
               print("math "+student)

   def biologyFailed(self):
       """
   iterates over every key/value pair of the "biology" dictionary and prints failed student
  
   """
       for student in self.biology:
           if self.biology[student]<60:
               print("biology "+student)

   def spanishFailed(self):
       """
   iterates over every key/value pair of the "spansih" dictionary and prints failed student
  
   """
       for student in self.spanish:
           if self.spanish[student]<60:
               print("spanish "+student)


g1=Grades()
g1.readfile()
g1.englishFailed()
g1.mathFailed()
g1.historyFailed()
g1.biologyFailed()
g1.spanishFailed()

Add a comment
Know the answer?
Add Answer to:
For each problem, you must: Write a Python program Test, debug, and execute the Python program...
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
  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • 1. Write and debug a MIPS program that performs the following operations . Prompt for and...

    1. Write and debug a MIPS program that performs the following operations . Prompt for and input three integers "a", "b and "c" using syscalls (3 points) Print all numbers starting from "a" upto "b" (including, but not exceeding "b") at an increment equal to value of"c"(5 points) If ba, then no numbers are printed, and a message is printed to inform it to the user. (3 points) Print the number and average of the generated numbers printed. (3 points)...

  • A)) (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He...

    A)) (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words. Here is how your program should work to simulate the ransom...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • (1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons...

    (1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons (;) or pound signs (#) should be ignored. All empty lines must be ignored Lines containing a string between square brackets are sections. Within each section, lines may contain numbers or strings. For each section, calculate the lowest, highest and modal (most common) number, and print it. In each section, also count all non-whitespace characters, and print that. Example input: ; this is a...

  • This part requires you to write two programs, compile them, and execute them - just like...

    This part requires you to write two programs, compile them, and execute them - just like our lab questions.  You may access these questions as many times as you need to and you have the entire duration of the test to complete these problems. You must submit the program code and the sample outputs for each problem - just like lab. These questions are worth 6 points each. 1.      C++ Write a program that reads 20 data values from a data...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Your program  write a program to test whether a number is prime or not. Your program should...

    Your program  write a program to test whether a number is prime or not. Your program should ask user to input an integer and respond: "Prime" or "Not prime". Don't use any library function that tests for prime numbers. The program should continue to ask for input, till it sees a 0, when it exits. Please submit printed pseudocodeshould ask user to input an integer and respond: "Prime" or "Not prime". Don't use any library function that tests for prime numbers....

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """...

    ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """ Computes the minimum and maximujm grades from grades and creates a list of two student names: first name is the student with minimum grade and second name is the student with the maximum grade. grades: list of non-negative integers names: list of strings Returns: list of two strings """ def main(): """ Test cases for minmaxgrades() function """ input1 = [80, 75, 90, 85,...

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