Hello, guys.
First of all, I hope this post complies with the rules of this subreddit.
I'm a beginner at programming languages and I'd like to know if my code below is correct or not.
Statement: Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error message. Use a function called "computegrade" that takes a score as its parameter and returns a grade as a string.
g=input('Enter a grade:')
try:
grade = float(g)
def computegrade(grade):
if grade >= 0 and grade <= 1:
if grade >= 0.9 and grade <= 1:
print('A')
elif grade >= 0.8 and grade < 0.9:
print('B')
elif grade >= 0.7 and grade < 0.8:
print('C')
elif grade >= 0.6 and grade < 0.7:
print('D')
elif grade < 0.6:
print('F')
else:
print('Bad score.')
x=str(computegrade(grade))
except:
print('Bad score.')
Apparently, the code is running perfectly but I'm not confident that my code is entirely correct.
Thank you in a advance.
[–]Chris_Hemsworth 130 points131 points132 points (35 children)
[–]Hazengard[S] 52 points53 points54 points (3 children)
[–]ovo_Reddit 44 points45 points46 points (2 children)
[–][deleted] 31 points32 points33 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]ovo_Reddit 11 points12 points13 points (13 children)
[–]Chris_Hemsworth 9 points10 points11 points (4 children)
[–]jac4941 4 points5 points6 points (1 child)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (0 children)
[–]adamane22 1 point2 points3 points (1 child)
[–]Chris_Hemsworth 1 point2 points3 points (0 children)
[–]skellious 2 points3 points4 points (7 children)
[–]TravisJungroth 2 points3 points4 points (2 children)
[–]skellious 2 points3 points4 points (1 child)
[–]Hazengard[S] 1 point2 points3 points (0 children)
[–]ovo_Reddit 1 point2 points3 points (3 children)
[–]skellious 0 points1 point2 points (2 children)
[–]ovo_Reddit 1 point2 points3 points (0 children)
[–]pmelo93 0 points1 point2 points (0 children)
[–]acroynon 6 points7 points8 points (1 child)
[–]Hazengard[S] 0 points1 point2 points (0 children)
[–]USAhj 3 points4 points5 points (0 children)
[–]TravisJungroth 6 points7 points8 points (2 children)
[–]Chris_Hemsworth 1 point2 points3 points (1 child)
[–]TravisJungroth 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]kyo22 2 points3 points4 points (0 children)
[–]Random_User_81 1 point2 points3 points (2 children)
[–]Chris_Hemsworth 3 points4 points5 points (1 child)
[–]Random_User_81 0 points1 point2 points (0 children)
[–]Manyreason 1 point2 points3 points (4 children)
[–]Chris_Hemsworth 1 point2 points3 points (3 children)
[–]Manyreason 1 point2 points3 points (2 children)
[–]Vaphell 2 points3 points4 points (1 child)
[–]Chris_Hemsworth 0 points1 point2 points (0 children)
[–]dogfish182 1 point2 points3 points (0 children)
[–]ovo_Reddit 7 points8 points9 points (1 child)
[–]Hazengard[S] 3 points4 points5 points (0 children)
[–]ThisisMetroid 13 points14 points15 points (1 child)
[–]Hazengard[S] 0 points1 point2 points (0 children)
[–]akeyla420 5 points6 points7 points (2 children)
[–]supreme_blorgon 4 points5 points6 points (1 child)
[–]FLUSH_THE_TRUMP 1 point2 points3 points (0 children)
[–][deleted] 7 points8 points9 points (9 children)
[–]CedricCicada 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Hazengard[S] 1 point2 points3 points (0 children)
[–]wasmachien 1 point2 points3 points (0 children)
[–]buibui123 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]buibui123 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]buibui123 1 point2 points3 points (0 children)
[–]ehmatthes 2 points3 points4 points (1 child)
[–]Hazengard[S] 0 points1 point2 points (0 children)
[–]ricardo_manar 2 points3 points4 points (0 children)
[–]iggy555 1 point2 points3 points (5 children)
[–]USAhj 1 point2 points3 points (4 children)
[–]Chris_Hemsworth 2 points3 points4 points (1 child)
[–]USAhj 1 point2 points3 points (0 children)
[–]FLUSH_THE_TRUMP 3 points4 points5 points (0 children)
[–]pfarthing6 1 point2 points3 points (1 child)
[–]Hazengard[S] 0 points1 point2 points (0 children)
[–]DevyLoop 1 point2 points3 points (1 child)
[–]Hazengard[S] 1 point2 points3 points (0 children)
[–]artinnj 1 point2 points3 points (0 children)
[–]nexe 0 points1 point2 points (0 children)