1
import sys
def main():
    keystr = input("Enter the Key: ")
    key = int(keystr)
    if (key <=0) or (key>=25):
        print("The key is out of range")
        sys.exit()

When I want to terminate with input of key (<= 0 or >= 25), there is an error messgae.

The key is out of rangeTraceback (most recent call last):
  File "C:/Users/USER/Desktop/caesarRefactored.py", line 38, in <module>
    main()
  File "C:/Users/USER/Desktop/caesarRefactored.py", line 11, in <module>
    sys.exit()
builtins.SystemExit:

How can I fix it? I'm running this on wing idle, the error shows. If on the terminal, it works just fine.

  • 2
    can't see the problem in the code shown – progmatico Jan 24 '18 at 22:04
  • 3
    Welcome to [SO]! I notice that your error message does not seem to correlate with your source code. In particular, `main()` is never invoked in your sample program. Please reduce your program to the shortest possible **complete** program that demonstrates the problem. Please copy-paste that program along with the actual and expected output. See [mcve] for more info. – Robᵩ Jan 24 '18 at 22:07
  • Your program behaves correctly. The purpose of `sys.exit` is to raise a `SystemExit` exception. – DYZ Jan 24 '18 at 22:09
  • I get no errors running your code on python 3.6.2 – Tyler Cowan Jan 24 '18 at 22:28
  • I'm runing it on wing idle 101 6.0. It has no problem on running terminal. – Zhuohao Gong Jan 25 '18 at 00:34
  • So it is the problem of running it on wing idle? – Zhuohao Gong Jan 25 '18 at 00:35

0 Answers0