Question

In: Computer Science

Please write in Python code please: Write a program that asks the user to enter 5...

Please write in Python code please:

Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main:

calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores

determine_grade – The function should accept a test score as an argument, and return a letter grade for the score based on the grading scale below:

85 or over HD
75-84 D
65-74 C
50-64 P
<50 F

Solutions

Expert Solution

# definig calc_average() function

def calc_average( sub1,sub2,sub3,sub4,sub5):
average= (sub1+sub2+sub3+sub4+sub5)/5
print("The average test score is : "+str(average))
# str() is used to explicitly convert 'float' object to string


# definig determine_grade function
def determine_grade( userScore):
if(userScore < 50 ):
return "F"
elif(userScore < 65 ):
return "P"
elif(userScore < 75 ):
return "C"
elif(userScore < 85 ):
return "D"
elif(userScore < 101 ):
return "HD"

# definig askForMarks function which will ask for input subject marks
def askForMarks():
sub1=float(input("Enter Marks of 1st Subject : "))
sub2=float(input("Enter Marks of 2nd Subject : "))
sub3=float(input("Enter Marks of 3rd Subject : "))
sub4=float(input("Enter Marks of 4th Subject : "))
sub5=float(input("Enter Marks of 5th Subject : "))
  
return sub1,sub2,sub3,sub4,sub5

# definig printResult function which will print the output result
def printResult(sub1,sub2,sub3,sub4,sub5):
   print("\nMarks\tLetter Grade")
   print(" "+str(sub1) +"\t\t"+determine_grade(sub1)+"\n",\
   str(sub2) +"\t\t"+determine_grade(sub2)+"\n",\
   str(sub3) +"\t\t"+determine_grade(sub3)+"\n",\
   str(sub4) +"\t\t"+determine_grade(sub4)+"\n",\
   str(sub5) +"\t\t"+determine_grade(sub5)+"\n")


def main():  
#call to askForMarks function
sub1, sub2, sub3, sub4, sub5 = askForMarks()
#call to printResult function
printResult(sub1, sub2, sub3, sub4, sub5)
#call to calc_average function
calc_average(sub1, sub2, sub3, sub4, sub5)

main()

'''

OUTPUT


Enter Marks of 1st Subject : 60
Enter Marks of 2nd Subject : 63
Enter Marks of 3rd Subject : 100   
Enter Marks of 4th Subject : 32
Enter Marks of 5th Subject : 70

Marks Letter Grade   
60.0 P
63.0 P
100.0 HD   
32.0 F
70.0 C

The average test score is : 65.0
'''


Related Solutions

---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter 5 test scores. The program will display a letter grade for each test score and an average grade for the test scores entered. The program will write the student name and average test score to a text file (“studentgrades.txt”). Three functions are needed for this program. def letter_grade( test_score) Test Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT