1

The aim of this code is to grade the score which is between 0.0 and 1.0. below 0.6 is F, >= 0.6 is D, >= 0.7 is C, >= 0.8 is B and >= 0.9 is A; and I'm getting an error.

inp = raw_input ('Enter score between 0.0 & 1.0 here: ')
if inp == > 0.9:
 print A 
elif inp == > 0.8:
 print B 
elif inp == > 0.7:
 print C
elif inp == >0.6:
 print D 
else inp < 0.6:
 print F 
6
  • In your code you have '== >' several times : what is that? Do you mean '>=' ? Commented Aug 17, 2015 at 20:58
  • yes. By '== >' i mean '>= '. am i doing it wrong...?? Commented Aug 17, 2015 at 21:07
  • 1
    Yes, you are doing it wrong. Where did you get the idea to do == >? Also, you'll need to change inp into a float and actually print strings like 'A' instead of unknown variables like A. That said, your current code's indentation appears correct. Commented Aug 17, 2015 at 21:16
  • @TigerhawkT3 idk... was doing kinda hit and try on this one... first days of coding here.. about float thing... can you elaborate it..?? Also i too noticed that i had to make A into strings to make it work.. thank you anyways Commented Aug 17, 2015 at 21:19
  • As @TigerhawkT3 mentions in a comment in one of the answers, it would be very helpful for yourself if you look through some basic Python documentation and/or tutorials for the appropriate syntax. Official Python tutorial. Commented Aug 17, 2015 at 21:27

2 Answers 2

2
inp = float(raw_input('Enter score between 0.0 & 1.0 here: '))  ## This line takes the raw input in from command prompt. float('') casts the raw_input string to a float type number. 
if inp >= 0.9:
    print "A"     
elif inp >= 0.8:
    print "B" 
elif inp >= 0.7:
    print "C"
elif inp >=0.6:
    print "D" 
else:
    print "F" 

Rewrite your code as above. You don't need to have a logical statement for "else" and you don't have 2 equal signs for greater than or equals. Also, remember to convert your string input to integer.

Use "input" instead of raw_input if your on python version 3 or higher.

inp = float(input ('Enter score between 0.0 & 1.0 here: '))
Sign up to request clarification or add additional context in comments.

8 Comments

still didnt work. got the error "syntax error: invalid syntax (score.py, line 2)
Sorry. Forgot to switch the => to >= to sign. Try this above.
What version of python are you using?. raw_input is not correct if you are using version 3 or higher. The other thing you could try, is to completely start a new python file.
oooooooh!!! it worked!!! thanks a billion!!! If u have time, can you please explain the above code...?? especially the first line with float..??
For more information on basic functions and tasks, I suggest reading the official Python tutorial.
|
1

Python knows where to end functions using indents/spaces. For example,

if(1 == 1):
    print "I indented here"

The code below causes an error because Python sees nothing is in the if statement

 if(1 == 1):
 print "I indented here"

2 Comments

sorry but i m getting another error now. if you read the code, please tell me what is wrong. the error says... " syntax error: invalid syntax (score.py, line 2) "
Could you post your code again or edit the existing code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.