Jan-05-2019, 11:00 AM
Hi,
No matter what number I select from the below code, the test() function is always fired. Why or, how to fix it?
TIA
No matter what number I select from the below code, the test() function is always fired. Why or, how to fix it?
TIA
#!/usr/bin/python3 import sys # to test it: # python3 testsys.py 1 # if we want to get 1 def f(x): return { '1':17, '2':18, '3':test(), '4':23, }[x] def test(): print('testing funtion') if __name__ == "__main__": try: a = f(sys.argv[1]) print('You selected {}'.format(a)) except RuntimeError: print('Runtime Error') except KeyError: print('Wrong number')