### Thread: Trouble writing a Python Program

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
6
Rep Power
0

#### 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

def main():
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.
2. 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
Code:
```if condition:
statements
elif another_condition:
statements
else:
print'F'#ailure```
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.)
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
6
Rep Power
0
Originally Posted by b49P23TIvg
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
Code:
```if condition:
statements
elif another_condition:
statements
else:
print'F'#ailure```
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.)
I ended up using elif statements and got it to work, dont know why I tried to use "but". Thanks for your help