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...
Write a python code that calculates π using numpy rand function.
Write a python code that calculates π using numpy rand function.
Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a...
Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a text encoded using Caesars encryption. The encryption key is unknown. The function returns the correct encryption key. Hint: Use the function we wrote was called caesar(c, key) and could encode a single character. # YOUR CODE GOES HERE def is_odd(n): return n%2 == 1 def caesar(c, key): """ Encrypts a lower case character c using key Example: if c = "a" and key=3 then...
Python file def calci(): grade = float(input("Enter your grade:")) while (grade <= 4): if (grade >=...
Python file def calci(): grade = float(input("Enter your grade:")) while (grade <= 4): if (grade >= 0.00 and grade <= 0.67): print("F") break elif (grade >= 0.67 and grade <= 0.99): print("D-") break elif (grade >= 1.00 and grade <= 1.32): print("D") break elif (grade >= 1.33 and grade <= 1.66): print("D+") break elif (grade >= 1.67 and grade <= 1.99): print("C-") break elif (grade >= 2.00 and grade <= 2.32): print("C") break elif (grade >= 2.33 and grade <=...
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’.
Python program please no def, main, functions Given a list of negative integers, write a Python...
Python program please no def, main, functions Given a list of negative integers, write a Python program to display each integer in the list that is evenly divisible by either 5 or 7. Also, print how many of those integers were found. Sample input/output: Enter a negative integer (0 or positive to end): 5 Number of integers evenly divisible by either 5 or 7: 0 Sample input/output: Enter a negative integer (0 or positive to end): -5 -5 is evenly...
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...
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...
#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() ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT