print("Please enter a numerical value between the range of 1.00 - 0.0")
if float(marks) >= 0.9:
x = print("Grade A")
elif float(marks) >= 0.8:
x = print("Grade B")
elif float(marks) >= 0.7:
x = print("Grade C")
elif float(marks) >= 0.6:
x = print("Grade D")
elif float(marks) < 0.6:
x = print("Grade F")
while True :
score = float(input("Enter your mark: "))
if score > 1.00 or score < 0.00:
The output is :
Grade is (the grade obviously)
Please Enter the numerical… etc.
Why is the raise occur??? I added a break after the print and the loop starts again… when i enter the wrong input obv the INV() activated which is nice.
compute_grade is printing the grade and then assigning the result of print to x. print always returns None, so it’ll always assign None to x. It’s then returning x, i.e. None, which is printed in the main loop.
Either print in compute_grade or return the grade from compute_grade and then print in the main loop, not both. The latter option is probably better.
Using raise on its own is for when you’re re-raising an exception that you’ve caught. If you’re raising an exception the first time, you must specify the exception that you’re raising, e.g. raise ValueError('invalid mark').
Using a ‘bare’ exception, i.e. except:, is a VERY bad idea because it catches ANY error. It even catches the exception generated by the incorrect use of raise! Always specify the exception that you want to catch and handle, e.g. except ValueError:.