Question

In: Computer Science

USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade...

USING PYTHON 3.7 AND USING def functions.

Write a function called GPA that calculates your grade point average (GPA) on a scale of 0 to 4 where A = 4, B = 3, C = 2, D = 1, and F = 0. Your function should take as input two lists. One list contains the grades received in each course, and the second list contains the corresponding credit hours for each course. The output should be the calculated GPA.

To calculate the grade points for a course, multiply the number of credit hours with the number corresponding to the earned grade. Add all the grade points for all the courses. Then divide the total grade points by the total number of credit hours for all the courses.

For example, the following record would result in a GPA of 2.75:

Solutions

Expert Solution

Program:

def GradePointAverage(Grade,Credit_hours): # called function

totalGrade=0 # initially  totalGrade is 0

Total_Credit_hours=0 # initially Total_Credit_hours is 0

for i in range(0,len(Grade)): # Loop to calculate total grade and total credit hours

if Grade[i]=='A':

totalGrade = totalGrade + 4 * Credit_hours[i]

Total_Credit_hours = Total_Credit_hours + Credit_hours[i]

if Grade[i]=='B':

totalGrade = totalGrade + 3 * Credit_hours[i]

Total_Credit_hours = Total_Credit_hours + Credit_hours[i]

if Grade[i]=='C':

totalGrade = totalGrade + 2 * Credit_hours[i]

Total_Credit_hours = Total_Credit_hours + Credit_hours[i]

if Grade[i]=='D':

totalGrade = totalGrade + 1 * Credit_hours[i]

Total_Credit_hours = Total_Credit_hours + Credit_hours[i]

if Grade[i]=='F':

totalGrade = totalGrade + 0 * Credit_hours[i]

Total_Credit_hours = Total_Credit_hours + Credit_hours[i]

GPA = totalGrade / Total_Credit_hours

print("Grade Point Average =",GPA)


Grade = ['A','B','A','C','D'] # Assign grade values to list

Credit_hours = [3,2,4,3,4] # Assign credit points to list

GradePointAverage(Grade,Credit_hours) # calling function

Output:


Related Solutions

In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
Python 3: Write a function called Interest with floating point parameters Amount and InterestPercent that calculates...
Python 3: Write a function called Interest with floating point parameters Amount and InterestPercent that calculates the simple interest on Amount using InterestPercent as the interest rate.The function should return the interest amount.
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and use a function named highest() that takes three inputs and returns the highest number. After you have got it working, try calling the function with inputs ‘hat’, ‘cat’, ‘rat’.
I need to write these three functions in Python using turtle module. def line(t, coord1, coord2)...
I need to write these three functions in Python using turtle module. def line(t, coord1, coord2) t is a turtle object passed in coord1 and coord2 are 2-element lists that represent x, y coordinates draws a line from coord1 to cord2 def poly(t, *coords) t is a turtle object passed in *coords is any number of x, y coordinates each as a 2-element list draws a polygon based on coords (will close off polygon by drawing a line from last...
Read the function definitions of the two functions: “compute_st_ave” and “compute_quiz_ave”. Write a function that calculates...
Read the function definitions of the two functions: “compute_st_ave” and “compute_quiz_ave”. Write a function that calculates the average of student averages. (Student averages are stored in st_ave [5] array). Include a statement to print this average on the screen. Declare this function above the “main” function where other functions are declared. In the main program, invoke this function. //Reads quiz scores for each student into the two-dimensional array grade //(but the input code is not shown in this display). Computes...
2. working with databases and files in python a) Write a function with prototype “def profound():”...
2. working with databases and files in python a) Write a function with prototype “def profound():” that will prompt the user to type something profound. It will then record the date and time using the “datetime” module and then append the date, time and profound line to a file called “profound.txt”. Do only one line per function call. Use a single write and f-string such that the file contents look like: 2020-10-27 11:20:22 -- Has eighteen letters does 2020-10-27 11:20:36...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist  An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
#Python 3.7 "Has no attribute" error - def get():     import datetime     d = date_time_obj.date()...
#Python 3.7 "Has no attribute" error - def get():     import datetime     d = date_time_obj.date()     return(d) print(a["Date"]) print("3/14/2012".get()) How to write the "get" function (without any imput), to convery the format ""3/14/2012" to the format "2012-03-14", by simply using "3/14/2012".get() ?
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
Python 3.7: Write the following decorators and apply them to a single function (applying multiple decorators...
Python 3.7: Write the following decorators and apply them to a single function (applying multiple decorators to a single function): 1. The first decorator is called strong and has an inner function called wrapper. The purpose of this decorator is to add the html tags of <strong> and </strong> to the argument of the decorator. The return value of the wrapper should look like: return “<strong>” + func() + “</strong>” 2. The decorator will return the wrapper per usual. 3....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT