Question

Write a Python program to prompt for a score between 0.0 and 1.0. If the score...

  1. Write a Python program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error message. If the score is between 0.0 and 1.0, print a grade using the following table:

    Score Grade >= 0.9 A
    >= 0.8 B
    >= 0.7 C

    >= 0.6 D

    < 0.6 F
    Run the program repeatedly as shown above to test different values for input. Here’s some sample input and output:

    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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of code:

output:

code:

n=int(input("Enter number of times to test: "))
for i in range(0,n):
x=input("Enter score: ")
if x>='0.0' and x<='1.0':
x=float(x)
if x<0.1 or x>1.0:
print("Bad score")
elif x>=0.9:
print('A')
elif x>=0.8:
print('B')
elif x>=0.7:
print('C')
elif x>=0.6:
print('D')
elif x<0.6:
print('F')
else:
print("Bad score")

#please upvote if this answer was helpful.

Add a comment
Answer #2

You can use the following Python program to achieve the desired functionality:

pythonCopy codedef get_grade(score):    if score >= 0.9:        return 'A'
    elif score >= 0.8:        return 'B'
    elif score >= 0.7:        return 'C'
    elif score >= 0.6:        return 'D'
    else:        return 'F'while True:    try:
        score = float(input("Enter score: "))        if 0.0 <= score <= 1.0:
            grade = get_grade(score)            print(f"Grade: {grade}")        else:            print("Bad score. Score must be between 0.0 and 1.0.")    except ValueError:        print("Invalid input. Please enter a numeric score.")

This program defines a function get_grade(score) to determine the grade based on the input score. The program then enters an infinite loop and repeatedly prompts the user for a score. If the input score is valid (between 0.0 and 1.0), it calculates the grade using the get_grade() function and prints it. If the input score is out of range or not a valid numeric value, appropriate error messages are displayed.

You can run the program, and it will continuously prompt for scores and display the corresponding grades until you terminate it manually. Try different input values to see the results.


answered by: Mayre Yıldırım
Add a comment
Know the answer?
Add Answer to:
Write a Python program to prompt for a score between 0.0 and 1.0. If the score...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT