Write a program in Python. This program will have three functions, the main() create() and retrieve(). main() will call create() and then call retrieve() create() will prompt the user to enter any number of course name / grade pairs and write them to a file named grades.txt. Pressing Enter with no input value on the course name will exit the loop, close the file, print "File was created and closed" and return the bool value True to the main() retrieve() will open and read grades.txt. The function then will print the course names and scores as shown below. The average score should be calculated as well as a simple GPA and displayed to two decimal places and then return variable used for the GPA to the main() . See sample run below in which 4 course names were entered, but note that more or fewer courses could have been entered. Tip: Simple GPA, In its easiest form, an A=4, B=3, C=2, D=1, F=0. For each class you have, you assign the correct number to the letter grade, add all of your grades together and divide by the number of classes you have taken. Score Letter GPA >= 90 A 4.0 >= 80 B 3.0 >= 70 C 2.0 >= 60 D 1.0 <60 F 0.0 Sample output: Enter course name or Enter to quit: ABE 1000 Enter grade (integer) achieved 96 Enter course name or Enter to quit: CAE 1000 Enter grade (integer) achieved : 77 Enter course name or Enter to quit: ANT 1000 Enter grade (integer) achieved : 79 Enter course name or Enter to quit: MAC 1000 File was created and closed Here are your grades: ABE 1000 score is 96 CAE 1000 score is 77 ANT 1000 score is 79 Average grade among your courses is 84.00 Your GPA is 2.67

Question

Write a program in Python. This program will have three functions, the main() create() and retrieve().

main() will call create() and then call retrieve()

create() will prompt the user to enter any number of course name / grade pairs and write them to a file named grades.txt. Pressing Enter with no input value on the course name will exit the loop, close the file, print "File was created and closed" and return the bool value True to the main()

retrieve()  will open and read grades.txt. The function then will print the course names and scores as shown below. The average score should be calculated as well as a simple GPA and displayed  to two decimal places and then return variable used for the GPA to the main() . See sample run below in which 4 course names were entered, but note that more or fewer courses could have been entered.

Tip: Simple GPA, In its easiest form, an A=4, B=3, C=2, D=1, F=0. For each class you have, you assign the correct number to the letter grade, add all of your grades together and divide by the number of classes you have taken.

Score Letter GPA
>= 90 A 4.0
>= 80 B 3.0
>= 70 C 2.0
>= 60 D 1.0
<60 F 0.0

Sample output: 

Enter course name or Enter to quit:  ABE 1000                                                Enter grade (integer) achieved 96                                                                    Enter course name or Enter to quit:  CAE 1000                                              Enter grade (integer) achieved : 77                                                                Enter course name or Enter to quit:  ANT 1000                                                Enter grade (integer) achieved : 79                                                                  Enter course name or Enter to quit:  MAC 1000                                              File was created and closed

Here are your grades:                                                                                      ABE 1000 score is 96                                                                                        CAE 1000 score is 77                                                                                        ANT 1000 score is 79                                                                                        Average grade among your courses is 84.00 Your GPA is 2.67

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Python

Programing Language

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: What is the difference between “Unit”, “Any” and “Nothing” in Kotlin?

A: "Any" is an open class and, by default, the superclass for all the classes, whether we define it exp...

Q: Produce a list of all customer names in which the first letter of the first and last names is in upp...

A: For people, it is easy to read the data in the combination of lowercase and uppercase letters rather...

Q: DataBase questions a. State and explain five (5) types of Database keys. b. Briefly explain four (4)...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

Q: In the following instruction sequence, show the values of the Carry, Zero, and Sign flagswhere indic...

A: Test operation is simply a bit-wise AND operation, which means, “00001111 &amp; 00000010” it gives “...

Q: Write a complete C program to calculate the average salary of the workers in a company. The program ...

A: Program code: //include the required header files #include&lt;stdio.h&gt; //define main function in...

Q: The function 'countPrimes' is given below to find the count of prime numbers enclosed within double ...

A: The correct option to replace the missing statement is: c num = atoi(a[j]);        if (num &lt; 2)  ...

Q: Use MatLab to solve:

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

Q: What do you call a tiny “switch” that can be set to either on or off?

A: Tiny switch The tiny switch has two phases either on or off. The bits are similar to positive or ne...

Q: what is  Independent Sub procedure ?

A: Independent Sub procedure: A term “Sub procedure” is abbreviated as a reserved “Sub”, which is a bl...

Q: Write a C++ code to program and arduino board to control 3 lights(red, yellow, green). Red stays ONf...

A: Let the three pins be Red, Yellow, and Green. Let Red pin be configured to 2, Yellow to 1, Green to ...

Q: Write a method that computes the sum of the digitsin an integer. Use the following method header:pub...

A: Program code: //include the required packages import java.util.Scanner; //define a class SumDigits ...

Q: Consider the following code fragments: If a = 10; Evaluate the new value of “b” in the following:(i)...

A: Since you have not mentioned the programming language so, we have executed the given code segment in...

Q: Write a program named filereader.py that reads and displays the data in friends.txt. This program sh...

A: 1. Open the file  2. Read the file line by line and split each line by Space and store it into the l...

Q: What is the key distinction between homogeneous and federated distributed database systems?

A: Federated Distributed Database systems is a type of heterogeneous database system. These systems are...

Q: Why would you employ the concept of prototyping in designing a system?

A: Prototyping in designing a system Prototyping helps to make changes easily and quickly. It focuses ...

Q: Implement the following method to sort the rows in a two-dimensionalarray. A new array is returned a...

A: Code: //import the required packages import java.util.Scanner;  //class definition public class Main...

Q: Following is the C++ program that calculates mortgage payment. To change the output statement that p...

A: Explanation: To display the interest rate with four decimal places the parameter value of setprecisi...

Q: What is the unsigned decimal representation of 1BF?

A: Decimal numbers are the numbers with base 10 containing digits 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. Hexa...

Q: Write the following queries in SQL, using the university schema. (We suggestyou actually run these q...

A: Explanation: In the below query, “Select”, “from”, “natural join”, “group by” and “where” are the k...

Q: What is an open port? Why is it important to limit the number of open ports asystem has to only thos...

A: Open Port: Open port is referred to as a Transmission Control Protocol (TCP)/ User Datagram Protoco...

Q: Develop a result sheet of 5 students in Chemistry, Mathematics and Physics (each out of 100) using a...

A: The program defines a structure as struct Marks. It has five members: roll_no of type int  name of...

Q: Could you explain the meaning of Firewall vulnerability exploit ?

A: The Firewall vulnerability exploit is an error or false design or assumption being made while implem...

Q: Ludo Ladders Game(C++)Structural code is given below of the project.Few parts of the code is removed...

A: Program defines a struct named Ludo with the following fields: Game an array of 100 and data type ...

Q: What is the unsigned decimal representation of 29F?

A: (29F)₁₆ = (2 × 16²) + (9 × 16¹) + (F × 16⁰) F=15 =2*256+9*16+15*1 =512+144+15 = (671)₁₀

Q: When the provided integer n is divisible by 3, print fizz. When the provided integer is divisible by...

A: PROGRAM EXPLANATION: - The program covers 4 cases for n. n is an integer number. When n is divisibl...

Q: (True/False): Linking OBJ modules is much faster than assembling ASM source files

A: The time taken to assemble large source files will be more and because of it the code is being broke...

Q: Q3, A lecturer intends to separate his students into 2 groups based on their INDEX Numbers, those wi...

A: Multiple question asked answering Q3, repost the remaining. Code: //header file #include &lt;iostrea...

Q: Assume that you have two files given : answer.txt and key.txt files. answer.txt file includes studen...

A: Programming instructions:   Include necessary header files. Declare required variales. Open the fil...

Q: Let's say that you have the following two paragraphs in your code: &lt;!DOCTYPE html&gt; &lt;html la...

A: Click to see the answer

Q: A Sub procedure named GetEndInv is passed four Integer variables from its calling statement. The fir...

A: Given statement: The given procedure header (a) states that all the variables except final are passe...

Q: Driver’s License Exam The local driver’s license office has asked you to create an application that ...

A: Create an application to grade the written driver’s license exam. The written driver’s license exam ...

Q: Why is the study of information system is important to you

A: Importance of study of information system Information systems are important in each level of busine...

Q: I have these two exercises and their answers, but I am not quite sure what is the behavior and why t...

A: EXPLANATION: - Two versions of mystery method is given. PROBLEM 1: - mystery method having integer p...

Q: Create a database whose tables are at least in 2NF, showing the dependency diagrams for each table.

A: Dependency diagram for database table The database table of Table1 is                    Table1 (...

Q: Write a C++ code to program and arduino board to control 3 lights(red, yellow, green). Red stays ON ...

A: Let the three pins be Red, Yellow and Green. Let Red pin be configured to 0, Yellow to 1, Green to 2...

Q: Identify and discuss each of the indicated dependencies.   Create a database whose tables are at l...

A: Functional dependency: when the information stored in the table can distinctly or uniquely determine...

Q: Which of the following commands can be used to enable a disabled constraint? ( refer to the tables i...

A: Explanation: “ALTER TABLE” statement comes under Data Definition Language. It is used to modify col...

Q: Write a program that lets the custom officer enter the total cars that were imported in last 12 mont...

A: NOTE: - Since, the programming language is not mentioned, so below code is implemented in java. PROG...

Q: Write a program whose input is two integers, and whose output is the first integer and subsequent in...

A: NOTE: - The code is implemented in C language, as programming language is not mentioned. PROGRAM EXP...

Q: 1) Write a pascal program that gives the following output with nested loops. Solutions with only wri...

A: Below is the required Pascal program: - Approach: - Defining the main program. Declaring the variab...

Q: How are repair programs arranged and run to prevent data leakage?

A: Data leakage prevention can be defined as the practice of detecting and preventing the unauthorised ...

Q: A lecturer intends to separate his students into 2 groups based on their INDEX Numbers, those withod...

A: Declare a static integer variable at class level, index, to hold the INDEX number of the student. st...

Q: Fat Percentage Calculator One gram of fat has 9 calories. If you know the number of fat grams in a p...

A: Form Design: View the Form Design in IDE. Set the Form Control properties in the Properties window.