Skip to content

Instantly share code, notes, and snippets.

@KKarthikeya
Last active November 9, 2022 11:06
Show Gist options
  • Save KKarthikeya/ec7e579b2a205978d351 to your computer and use it in GitHub Desktop.
Save KKarthikeya/ec7e579b2a205978d351 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 print A, Grade >= 0.8 print B, Grade >= 0.7 print C, Grade>= 0.6 print D, Grade < 0.6 print F If the user enters a value out of range, print a su…
score = float(raw_input("Enter score between 0.0 and 1.0: "))
if score>1.0 or score<0.0 :
print "error"
elif 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'
@Geojo222
Copy link

Geojo222 commented Feb 6, 2017

what if input is a string

@jsbd29
Copy link

jsbd29 commented Aug 1, 2017

Your program does not have any output

@Spandhana9788
Copy link

what if input is a string

you will get an error stating that "couldn't convert string to float"

@Spandhana9788
Copy link

there is an error in line 2,we should not use and operator
it is suppose to be like -->if score>=1.0 or score<0.0

@Sassie98
Copy link

Sassie98 commented May 2, 2020

image

@devtayo
Copy link

devtayo commented May 3, 2020

#This works

score=input('Enter score: ')
try:
sc=float(score)
except:
print('Sorry, try a number.')
quit()
if float(score) > 1.0 or float(score) < 0.0 :
print('Sorry, not in range')
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')

@mahesh12021999
Copy link

sc = (input('enter the score: '))

def grades():
if score >=0.0 and score <=10.0 :
if score >=0.9:
print("a")
elif score>=0.8:
print('b')
elif score>=0.7:
print('c')
else:
print('fail')
else:
print("out of range")
try:
score=float(sc)
except:
print('bad score')
quit()
grades()

@SabbirTareq
Copy link

image

Copy link

ghost commented May 22, 2020

score= input('Enter score : ')
try:
scr= float(score)
except:
print("Enter a valid number and try again")
quit()

if scr <= 1.0:

if scr >= 0.9:
        print('A')
elif scr >= 0.8:
        print('B')
elif scr >= 0.7:
        print('C')

elif scr >= 0.6:
        print('D')

elif scr <0.6:
        print('F')

else:
print('Input out of range ,Please correct it')

@amanr4
Copy link

amanr4 commented May 24, 2020

this works perfectly.
make sure you give some space before writing print(don't make indentation error).

score=input("Please type a score between 0.0 and 1.0:")
try:
float(score)
if float(score) >1.0 and float(score) < 0mmm.0:
print("error")
if float(score) >= 0.9 and float(score) <= 1.0:
print("A")
elif float(score) >= 0.8 and float(score) <= 0.9:
print("B")
elif float(score) >= 0.7 and float(score) <= 0.8:
print("C")
elif float(score) >= 0.6 and float(score) <= 0.7:
print("D")
elif float(score) > 0 and float(score) <= 0.6:
print("F")
else:
print("enter valid score.")
except:
print("enter valid score.")

@Jdon707
Copy link

Jdon707 commented May 26, 2020

score = float(input("Enter score between 0.0 and 1.0: "))
if score>1.0 or score<0.0 :
print ("error")
elif 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')

@richhaa
Copy link

richhaa commented May 29, 2020

score= input('Enter score : ')
try:
scr= float(score)
except:
print("Enter a valid number and try again")
quit()

if scr <= 1.0:

if scr >= 0.9:
        print('A')
elif scr >= 0.8:
        print('B')
elif scr >= 0.7:
        print('C')

elif scr >= 0.6:
        print('D')

elif scr <0.6:
        print('F')

else:
print('Input out of range ,Please correct it')

@richhaa
Copy link

richhaa commented May 29, 2020

This says bad input on line 3

@sanchit7892
Copy link

sanchit7892 commented May 29, 2020

TRY THIS!
score=input("Please type a score between 0.0 and 1.0:")
try:
float(score)
if float(score) >= 0.9 and float(score) <= 1.0:
print("A")
elif float(score) >= 0.8 and float(score) <= 0.9:
print("B")
elif float(score) >= 0.7 and float(score) <= 0.8:
print("C")
elif float(score) >= 0.6 and float(score) <= 0.7:
print("D")
elif float(score) > 0 and float(score) <= 0.6:
print("F")
else:
print("Bad score. Please run the program again.")
except:
print("Bad score. Please run the program again.")

@benopoku
Copy link

benopoku commented May 29, 2020

#This works simple
score = input("Enter Score: ")
try:
scr= float(score)
except:
print("Sorry, enter a valid number to proceed...!")
quit()
#below syntax checks for the number between 1.0 and 0.0.
if scr > 1.0 or scr < 0.0:
print('Sorry, not in the range')
elif scr >= 0.9:
print('A')
elif scr >= 0.8:
print('B')
elif scr >= 0.7:
print('C')
elif scr >= 0.6:
print('D')
else :
print('F')

@sejal-bansal
Copy link

#This worked. Easy to understand, give this a try.
score = input("Enter Score: ")
try:
x = float(score)
except:
print("Error")

if 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("Please Enter a valid score")

@seventhsoul
Copy link

score = float(raw_input("Enter score between 0.0 and 1.0: "))
if score>1.0 or score<0.0 :
print ("error")
elif 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")

@safafmohammed
Copy link

#This works perfectly guys
score=input("Please type a score between 0.0 and 1.0:")
try:
s=float(score)
if s >= 0.9 and s <= 1.0:
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")
elif s > 0 and s <= 0.6:
print("F")
else:
print("Bad score. Please run the program again.")
except:
print("Bad score. Please run the program again.")

@ik-lab
Copy link

ik-lab commented Jun 9, 2020

try this

score = input("Enter score: ")
score = float(score)
if score>1.0 or score<0.0 :
print ("error")
elif 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")

@basildoesstuff
Copy link

#coursea code assignment 3.3
score = float(input("Enter score between 0.0 and 1.0: "))
if score>1.0 or score<0.0 :
print ("error")
elif 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")

@Ayush20118
Copy link

`score = input("Enter Score: ")
x = float(score)
if 0.0 < x > 1.0:
print("Score is out of range")
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")

`

@aneekbanerjee86
Copy link

score = input('Enter a Score between 0.0 to 1.0: ')

if 0.0 <= float(score) <= 0.6:
print('F')
elif 0.6 <= float(score) <= 0.7:
print('D')
elif 0.7 <= float(score) <= 0.8:
print('C')
elif 0.8 <= float(score) <= 0.9:
print('B')
elif 0.9 <= float(score) <= 1.0:
print('A')
else:
print("the score is out of range")

@Mayank3008
Copy link

try:
inp = raw_input("Enter a number between 0.0 and 1.0: ")
score = float(inp)
if (score >= 1.0):
print("You didn't follow instructions")
exit()
elif (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")
except:
print("Please enter numerical numbers")
exit()

"Try this code it works accurately".

@JZ-Jun
Copy link

JZ-Jun commented Aug 4, 2020

this works


score = input("Enter Score: ")
try:
scr = float(score)
except:
print("Sorry, enter a valid number to proceed...!")
quit()

if scr > 1.0 or scr < 0.0:
print('Sorry, not in the range')
elif scr >= 0.9:
print('A')
elif scr >= 0.8:
print('B')
elif scr >= 0.7:
print('C')
elif scr >= 0.6:
print('D')
else:
print('F')

@casstom
Copy link

casstom commented Mar 21, 2021

score=input("Please type a score between 0.0 and 1.0:")
try:
float(score)
if float(score) >= 0.9 and float(score) <= 1.0:
print("A")
elif float(score) >= 0.8 and float(score) <= 0.9:
print("B")
elif float(score) >= 0.7 and float(score) <= 0.8:
print("C")
elif float(score) >= 0.6 and float(score) <= 0.7:
print("D")
elif float(score) > 0 and float(score) <= 0.6:
print("F")
else:
print("Bad score. Please run the program again.")
except:
print("Bad score. Please run the program again.")

There was an error but this fixes it:

score=input("Please type a score between 0.0 and 1.0: ")
try:
score = float(score)
except:
print("Bad score")
exit(0)
if float(score) >= 0.9 and float(score) <= 1.0:
print("A")
elif float(score) >= 0.8 and float(score) <= 0.9:
print("B")
elif float(score) >= 0.7 and float(score) <= 0.8:
print("C")
elif float(score) >= 0.6 and float(score) <= 0.7:
print("D")
elif float(score) > 0 and float(score) <= 0.6:
print("F")
else:
print("Bad score")

@sreecar
Copy link

sreecar commented May 15, 2021

score = input('Enter score: ')
s = float(score)
if s >= 0.9 and s <= 1.0:
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')
elif s < 0.6 and s > 0.0 :
print('F')
else :
try:
if s <= 0.0 or s >= 1.0 :
print('Error,Score is out of range.Please enter score between 0.0 and 1.0')
except :
quit()

@gongarnue
Copy link

Improve your grogram in Question 1 by adding try and except. If a non-numeric input is
submitted, your program should print a message and exit the program.
Example input and output:
Enter Hours: 50
Enter Rate: ten
Error, please enter a numeric dat

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