r/pythonhelp • u/dredgedskeleton • May 18 '20
Hopefully a simple solve
Hi all -- I'm a masters student in NYC and am taking a very rudimentary software design class. As part of our final, we are supposed to create a very simple MVP to write documentation on. I'm running into some issues with my Python code and hope you may be of some help!
Basically, I am trying to create a program that compares and input variable against a list/set/dictionary of words. I hope to make it more complex, but as of now -- I am just asking that the user pop in a string and then the program will spit out whether the string exists in the list/set/dictionary.
Without providing my lists (they are huge), here's what the code looks like:
leveler = input("Please choose grade: K or G1 >> ")
if leveler == 'K' :
input("Please input word for Kindergarten leveling: ")
elif leveler == 'G1' :
input("Please input word for Grade 1 leveling: ")
kindergarten_list = ['a', 'b', 'c']
grade1_list = ['x', 'y', 'z']
kindergarten_set = set(kindergarten_list)
grade1_set = set(grade1_list + kindergarten_list)
if leveler in kindergarten_set :
print ('True')
if leveler not in kindergarten_set :
print ('False')
No matter what I enter, I get a "False." Any idea why?
Also, I am hoping to make this program more complex as long as it isn't a huge lift. Instead of entering words against the lists/sets, I want to enter a sentence. Then I want the program to spit out whatever words are NOT part of the given list/set.
Thanks in advance for any help!
1
u/someoneonboard1 May 18 '20
Your leveler is either K or G1. So it will never be in kindergarten_set. Thus always false. Your input("Please input word for Kindergarten leveling: ")
Is not right. If you want to use what the user entered then you need to assign this to a value just like you did leveler = input(........) Same for Grade 1 leveling line as well.