Question

In: Computer Science

Rewrite the grade program from Question 2.2 using a user-defined function called computegrade that takes a...

Rewrite the grade program from Question 2.2 using a user-defined function called computegrade that takes a score as its parameter and returns a grade as a string. (15 points) USING PYTHON LANGUAGE

>= 0.9   A
>= 0.8   B
>= 0.7   C
>= 0.6   D
<  0.6   F

Run the program repeatedly as shown below to test the various different values for input.

Enter score: 0.95
A

Enter score: perfect
Bad score

Enter score: 10.0
Bad score

Enter score: 0.75
C

Enter score: 0.5
F

Solutions

Expert Solution

SOLUTION-
I have solve the problem in python code with comments and screenshot for easy understanding :)

CODE-

#python code
def computegrade(score):
try:
score = float(score)
#grades according to score
if score > 1:
return "Bad score"
elif score >= 0.9:
return "A"
elif score >= 0.8:
return "B"
elif score >= 0.7:
return "C"
elif score >= 0.6:
return "D"
elif score >= 0:
return "F"
else:
return "Bad score"
except ValueError:
return "Bad score"

#loop to ask user to enter score
for i in range(5):
score = input("Enter score: ")
print(computegrade(score))
print()


SCREENSHOT-


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

(EXCEL) Create a user-defined function called Hexagon that takes one argument called side and returns the...
(EXCEL) Create a user-defined function called Hexagon that takes one argument called side and returns the area of a regular hexagon given the length of the side. Show that the function works in a worksheet by inserting the formula somewhere.
Question) The following simple shell program/code using gets() function to obtain input from user. Using the...
Question) The following simple shell program/code using gets() function to obtain input from user. Using the gets() function is potentially dangerous and it allows buffer to overflow. You need to do following modification in the code; (a) change the provided code so that you now use fgets() function instead of fget() to obtain input from the user, (b) make any other necessary changes in the code because of using fgets() function, and (c) fill in the code for the exectute()...
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user...
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin.
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an...
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an integer n and returns 1 if n is a perfect number, otherwise it will return 0. If the sum of a number’s proper divisors are equal to the number, than the number is called a perfect number. For example, 6 is a perfect number: 6=1+2+3.
Write a user-defined function named printBox that, when called, will output the following sequence of characters:...
Write a user-defined function named printBox that, when called, will output the following sequence of characters: OOOOOOOO OOOOOOOO OO            OO OO            OO OOOOOOOO OOOOOOOO Write a user-defined function named printArrow that, when called, will accept an integer called arrowSize and will output a sequence of *’s such that there are arrowSize number of rows with the number of * incrementing, and then arrowSize-1 rows with the number of * decrementing: If arrowSize = 3, then the output is: * **...
how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
MATLAB Write a user defined function for a projectile motion. If a ball is launched from...
MATLAB Write a user defined function for a projectile motion. If a ball is launched from initial position(0,0) with a velocity v0 at angle θ, determine your horizontal and vertical position. Please plot x vs. t, y vs. t and y vs. x.
Question about user defined function.(language:c++) If I were to make function, for example, bool Function(char i){...
Question about user defined function.(language:c++) If I were to make function, for example, bool Function(char i){ If(i=='a') return true; return false; } In this situation, I want to use this function for main1.cpp, main2.cpp, and main3.cpp. To do that, I want to use this function as a header file to save time. In Funtion.h file, I write bool Function(char i); between #ifndef,#define and #endif. (1) In Function.cpp file, I write the body of Function(char i) after I put #Function.h (2)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT