Python Forum
when I type either C B or A nothing appears
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
when I type either C B or A nothing appears
#1
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?
Reply
#2
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.
Recommended Tutorials:
Reply
#3
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).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The int that appears an odd number of times. MeeranRizvi 6 6,535 Dec-30-2016, 09:54 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020