November 28th, 2012, 08:50 PM
Trouble writing a Python Program
I need help with writing a python code to print out a students letter grade. It seems to be fairly simple, but I am new to this and I am really struggling.
The ranges are, A is 100 - 90, B is 89 - 80, C is 79 - 70, D is 69 - 61 and F is 60 or lower.
Currently I have this but, no clue if it is right or even going in the right direction
y = input("Enter the exam score between 0 and 100")
if y >= 90 print: "A"
if y <= 89 but >= 80 print: "B"
if y <= 79 but >= 70 print: "C"
if y <= 69 but >= 61 print: "D"
if y <= 60 print: "f"
Thank you, I really appreciate any help.
November 28th, 2012, 08:59 PM
Most of all, run your program in the python interpreter. You'd learn that "but" isn't recognized by python.
python has unusual comparisons, you can actually write the comparison as
if 80 <= y <= 89: print "B"
then furthermore you can use a chain of
Needless to say, this is a more efficient technique because your computer doesn't need to make as many comparisons.
Note: python is the only language I know for which comparison strings longer than a single comparison of less-than greater-than evaluate as they would algebraically. (I don't know ruby.)
[/code] are essential for python code and Makefiles!
November 29th, 2012, 08:56 AM
I ended up using elif statements and got it to work, dont know why I tried to use "but". Thanks for your help
Originally Posted by b49P23TIvg