Python Forum
when I type either C B or A nothing appears - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: when I type either C B or A nothing appears (/thread-12118.html)



when I type either C B or A nothing appears - Samp97 - Aug-10-2018

I’ve typed this code and it won’t work any help?:

grade = raw_input(“Enter your grade:”)
grade = [“F”, “E”, “D”, “C”, “B”, “A”]
If grade >= “C”:
 print’you are permitted’
But when I type either C B or A nothing appears?


RE: Need help! - metulburr - Aug-10-2018

what else do you expect? Im assume you are expecting a range of numbers for each grade letter? But you are just comparing whatever the user inserts to a capital char.


RE: when I type either C B or A nothing appears - ichabod801 - Aug-10-2018

I think the main problem is that you assign the user input to the grade variable on line 1, and then over write the grade variable with a list on line 2. So on line 3 you are comparing a character to a list, which just doesn't work.

Also note that strings compare alphabetically. So 'D' will be greater than 'C' (and counted as a pass by your code), whereas 'A' will be less than 'C' (and counted as a fail).


RE: when I type either C B or A nothing appears - DuaneJack - Aug-15-2018

In ASCII characters, each letter or number or special character has a numerical value, ie:
A is 65
B is 66
C is 67
D is 68
E is 69
F is 70

if the user does not have their cap locks key on or use capital letters then it also will not work so please research on how to force caps on via the .upper() method.

I am a noob and I use python 3 so maybe I am wrong but your method to print('text in here') may need parenthesis, it appears you are using python 2.

In line 1 put a space after the colon:
“Enter your grade: ” so the users answer is not jammed up next to the colon when it prints out.