My code is not printing, how do I get it to do so? - 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: My code is not printing, how do I get it to do so? (/thread-21141.html) |
My code is not printing, how do I get it to do so? - celtickodiak - Sep-16-2019 print('Enter number grade.') grade = input() if int(grade) < 60: print('F') elif int(grade) == (60, 61, 62): print('D-')The beginning to my code, it goes all the way up to the highest grade, my problem is, any number entered 60 or more, will simply not print the letter grade, where anything under 60 prints the F. Why are none of the other numbers printing their corresponding letter grade? RE: My code is not printing, how do I get it to do so? - ThomasL - Sep-16-2019 Because you are checking if the integer value of your input grade is equal to (60, 61, 62) which is a tuple and this condition can never be True so the print() function is never called RE: My code is not printing, how do I get it to do so? - buran - Sep-16-2019 look at line 5: on right side you have tuple - (60, 61, 62) on left side - int number - int(grade) number and tuple can not be equal (i.e. that is comparing apples and bananas) make line 5 elif int(grade) in (60, 61, 62):
RE: My code is not printing, how do I get it to do so? - ThomasL - Sep-16-2019 You could check it this way: elif int(grade) == 60 or int(grade) == 61 or int(grade) == 62:which gets inconvenient if you want to check for even more values so this might be one alternative elif int(grade) in [60, 61, 62]:of you check the range of the input: elif int(grade) > 59 and int(grade) < 63: RE: My code is not printing, how do I get it to do so? - perfringo - Sep-17-2019 Is 'if' a requirement? for-loop seems more suitable for task at hand. |