Skip to content

Instantly share code, notes, and snippets.

@Mohamed2del
Created June 9, 2018 15:09
Show Gist options
  • Save Mohamed2del/a69a57dde82453a963c86af915b08feb to your computer and use it in GitHub Desktop.
Save Mohamed2del/a69a57dde82453a963c86af915b08feb to your computer and use it in GitHub Desktop.
Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. 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 If the user enters a value out of range, print a suitable error message and exit
score = input("Enter Score: ")
s = float(score)
x = 'Error'
if s >= 0.9:
x = 'A'
elif s >=0.8:
x='B'
elif s >=0.7:
x='C'
elif s >= 0.6:
x='D'
elif s < .6:
x ='F'
else:
x ="Out of Range"
print (x)
@Suhailazaid
Copy link

it work:)
score = input("Enter Score: ")
gr=float(score)
if gr<1 :
if gr>=0.9:
print("A")
elif gr>= 0.8 :
print("B")
elif gr>= 0.7:
print("C")
elif gr>= 0.6 :
print("D")
elif gr< 0.6 :
if gr>0:
print("F")
else:
print("sorry error input please exite")

@Praju-Gowda
Copy link

score = raw_input("enter a score:")
s = float(score)
if 0.0 <= s <= 1.0:
if s >= 0.9:
result = "A"
print result
elif 0.8 <= s < 0.9:
result = "B"
print result
elif 0.7 <= s < 0.8:
result = "C"
print result
elif 0.6 <= s < 0.7:
result = "D"
print result
else:
result = "F"
print result
else:
print "Error: score out of range"

@yuriszc
Copy link

yuriszc commented Nov 18, 2021

score = input("Enter Score: ")
s = float(score)
try:
if s >= 0.9:
print("A")
elif s >= 0.8:
print("B")
elif s >= 0.7:
print("C")
elif s >= 0.6:
print("D")
elif s < 0.5:
print("F")
except:
print("Input a value in the range between 0.0 and 1")

@asaadmansour
Copy link

score = input("Enter Score: ")
s = float(score)
if 1.0> s >= 0.9:
print('A')
elif 0.9>s >= 0.8:
print('B')
elif 0.8>s >= 0.7:
print('C')
elif 0.7>s >= 0.6:
print('D')
elif 0.0<s < 0.6:
print('F')
else:
print('x out of range')

@ElnurAskarov
Copy link

score = input("Enter Score: ")
s=float(score)
if s>1:
print("Error")
quit()
elif s>=0.9:
print("A")
elif s>=0.8:
print("B")
elif s>=0.7:
print("C")
elif s>=0.6:
print("D")
elif s<0.6:
print("F")

@ADERDOUR-Achraf
Copy link

score = input("Enter Score: ")
try :
s=float(score)
except:
print("error")
quit()

if s >= 0.9:
print("A")

elif s >= 0.8:
print("B")

elif s >= 0.7 :
print("C")

elif s >= 0.6:
print("D")

if s < 0.6 :
print("F")

@BunnyRon
Copy link

BunnyRon commented May 4, 2022

score = input("Enter Score: ")
s = float(score)
if s<0.0 or s>1.0:
print("wrong")
exit()

if s<0.6:
print("F")
elif s<0.7:
print("D")
elif s<0.8:
print("C")
elif s<0.9:
print("B")
else:
print("A")

@anushrutm
Copy link

anushrutm commented Jun 23, 2022

This one works fine

score = input("Enter Score: ")
try:
s = float(score)
if(s<=1):
if(s>=0.9):
print("A")

    elif(s>=0.8):
        print("B")
    
    elif(s>=0.7):
        print("C")
    
    elif(s>=0.6):
        print("D")
    
    elif(s<0.6):
        print("F")
 
elif(s>1):
    print("Error! Score exceeds 1.0")

except:
print("Error! Not a Number")
quit()

@Aliqasim222
Copy link

My code is easy to understand and simple and will work in all conditions
I hope this helps.

score = input("Enter Score: ")
sc = float(score)

if sc>1.0:
print("Error")
elif sc>=0.9 and sc<1.0:
print("A")
elif sc>=0.8 and sc<0.9:
print("B")
elif sc>=0.7 and sc<0.8 :
print("C")
elif sc>=0.6 and sc<0.7:
print("D")
elif sc<0.6:
print("F")

@TaiyebNamdaran
Copy link

try:
score=float(input("Enter Score: "))
except:
print("Data type Error, Enter a numeric")
quit()

if score > 1.0 or score<0.0 :
print("Number is out of Range, Enter a number between 0.0 to 1.0")
quit()

if score>=0.9:
print("A")
elif score>=0.8:
print("B")
elif score>=0.7:
print("C")
elif score>=0.6:
print("D")
else:
print("F")

@atiqur24
Copy link

atiqur24 commented Sep 3, 2022

score = input("Enter Score: ")
s = float(score)
if 0<=s<=1:
if s >= 0.9:
x = 'A'
elif s >=0.8:
x='B'
elif s >=0.7:
x='C'
elif s >= 0.6:
x='D'
else:
x ='F'
print(x)
else:
print("your value is out of range")

@ishikaj046
Copy link

score = input("Enter Score: ")
istr = float(score)
if istr > 1.0:
print ('THE GIVEN NUMBER IS OUT OF RANGE. PLEASE ENTER ANUMBER BETWEEN 0.0 AND 0.1')
elif istr>=0.9:
print('A')
elif istr>=0.8:
print('B')
elif istr>=0.7:
print('C')
elif istr>=0.6:
print('D')
else:
print('F')

Other codes appeared too complicated so here's a simple code that I wrote as a very beginner

@DrNusratRabbani
Copy link

score = input("Enter Score: ")
S=float(score)
if S>= 0.9:
print("A")
elif S>= 0.8:
print("B")
elif S>= 0.7:
print("C")
elif S>= 0.6:
print("D")
elif S>= 0.6:
print("F")
else:
print("out of range")

@WestonSpiro
Copy link

score = input("Enter Score: ")
try:
s = float(score)
except:
print("Please Enter A Number between 0.0 & 1.0")

if s >= .9:
print("A")
elif s >= .8:
print("B")
elif s >= .7:
print("C")
elif s >= .6:
print("D")
else:
print("F")

@iamAhmad002
Copy link

s = input('Enter Score:')
score = float(s)
x = 'Error'
if score==0.9:
print('A')
elif score==0.8:
print('B')
elif score==0.7:
print('C')
elif score==0.6:
print('C')
elif score<0.6 :
print('F')
else :
print("Error")

@intlconxun
Copy link

try:
    score = float(input('Enter score: '))
    if score < 0 or score > 1:
        raise ValueError
except:
    print('Bad Score')
    quit()

grade = 'F'

if score >= 0.9:
    grade= 'A'
elif score >= 0.8:
    grade = 'B'
elif score >= 0.7:
    grade = 'C'
elif score >= 0.6:
    grade = 'D'

print(grade)

this works. great job!! thank you

@signaloninternet
Copy link

this is the best one

score = input("Enter Score: ")
try:
    s = float(score)
except:
    print("Bad score")
    quit()
    
if s > 1.0:
    print("Bad score, Enter a valid score")
    quit()
if s < 0.0:
    print("Bad score, Enter a valid score")
    quit()
elif s >= 0.9:
    print("A")
elif s < 0.9 and s >= 0.8:
    print("B")
elif s < 0.8 and s >= 0.7:
    print("C")
elif s < 0.7 and s >= 0.6:
    print("D")
elif s < 0.6:
    print("F")
else:
    print("Bad score")

@CristianoFIlho
Copy link

score = input("Enter Score: ")
try:
s = float(score)
except:
print("Bad score")
quit()

if s > 1.0 or s < 0.0:
print("Bad score, Enter a valid score")
quit()
elif s >= 0.9:
print("A")
elif s >= 0.8 and s < 0.9:
print("B")
elif s >= 0.7 and s < 0.8:
print("C")
elif s >= 0.6 and s < 0.7:
print("D")
else:
print("F")

@pavanydg
Copy link

score = input('Enter the score:')
try:
float(score)
if float(score)>1.0 or float(score)<0:
print('Bad score')
elif float(score) >= 0.9 :
print('A')
elif float(score) >= 0.8:
print('B')
elif float(score) >= 0.7:
print('C')
elif float(score) >= 0.6:
print('D')
else :
print('F')
except:
print('Bad score')

@tahira2k16
Copy link

score = input("Enter Score: ")
try:
Fscore = float(score)
except:
print("Enter Numeric Number")
quit()
if Fscore >= 1.0:
if Fscore < 0.0:
print("Enter Value Between 0.0 and 1.0")
quit()
if Fscore >= 0.9:
print("A")
elif Fscore >= 0.8:
print("B")
elif Fscore >= 0.7:
print("C")
elif Fscore >= 0.6:
print("D")
elif Fscore < 0.6:
print("F")

@sugarbaeslayr
Copy link

sugarbaeslayr commented Feb 10, 2023

s=input("score")

sc=float(s)

x=("error")

if sc >1:
print(x)
exit()
elif sc >= 0.9:
x= ('A')
elif sc >= 0.8:
x = ('B')
elif sc >= 0.7:
x = ('C')
elif sc >= 0.6:
x = ('D')
elif sc < 0.6:
x = ('F')

else:
x=("error message")

print(x)

@Seharish-Fatima
Copy link

print('Enter A Score Between 0.0 and 1.0')
score=float(input())
if score>=0.9 and score<=1.0:
print('A')
elif score>=0.8 and score<0.9:
print('B')
elif score>=0.7 and score<0.8:
print('C')
elif score>=0.6 and score<0.7:
print('D')
elif score<0.6:
print('F')
else:
print('Bad Score')

@Adenike998
Copy link

score = input("Enter Score: ")
s = float(score)
if s > 1.0:
print('error')
elif s == 1.0:
print('A')
elif s >= 0.9:
print('A')
elif s >= 0.8:
print('B')
elif s >= 0.7:
print('C')
elif s >= 0.6:
print('D')
elif s< 0.6:
print('F')

@Abdul36
Copy link

Abdul36 commented Nov 30, 2023

xx= input("enter the grade: ")
x= float(xx)
if x > 1:
print("Number is out of Range")
print("Enter number between 0.0 to 1.0")
elif x <=0:
print("Number is out of Range")
print("Enter number between 0.0 to 1.0")
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")
**Hope so it works ** suggestions are appreciated at [email protected]

@j5210251
Copy link

score = input("Enter Score: ")
try:
s = float(score)
except:
print("Out of range")
quit()
if s > 1.0:
print("Out of range")
elif s >= 0.9:
print("A")
elif s >=0.8:
print("B")
elif s >=0.7:
print("C")
elif s >= 0.6:
print("D")
elif s < 0.6:
print("F")
else:
print("Out of range")

@YogaSarvan
Copy link

score = input("Enter Score: ")
s = float(score)
if s >= 0.9:
print('A')
elif s >= 0.8:
print ('B')
elif s >= 0.7:
print('C')
elif s >= 0.6:
print('D')
elif s< 0.6:
print('F')
else:
print(" Out of range ")

@Thattastyturtle
Copy link

score = input("Enter Score: ")
try:
s = float(score)
except:
print("Please type a numeric value in between 0.0 - 1.0")
quit()
if s > 1.0 or s < 0:
print("Please enter a grade in range of 0.0 - 1.0")
quit()
elif s >= 0.9:
print("A")
elif s >= 0.8:
print("B")
elif s >= 0.7:
print("C")
elif s >= 0.6:
print("D")
elif s < 0.6:
print("F")
elif s > 1.0 or s < 0:
print("Please enter a grade in range of 0.0 - 1.0")
quit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment