python - Using a dictionary as an answer key for user input -


this meant break out of loop when user enters file extension in dictionary:

def ext_input():     ext_dict = {'doc', 'docx', 'pdf', 'rtf', 'txt', 'wps', 'csv'}     while true:         print('enter file extension (.pdf, .txt, etc..) type "help" list of extensions')         fileext = input()         if fileext == "help":             print(ext_dict)             return         elif fileext != ext_dict:             print('please enter correct file extension (.pdf, .txt, etc..) type "help" list of extensions')         else:             print("\"%s\" has been selected" % fileext)             break 

still relatively new python, pointers in right direction great

first, help_dict not dict, it's set.

second: you're comparing string set - of course won't never ever compare equal. testing if set contains element done in operator: if in myset: - , non-appartenance use not in. iow, want:

elif fileext not in ext_dict:    # xxxx 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -