Why does this 'sys' is not defined error occur?

Asked

Viewed 559 times

2

Why does this error occur name 'sys' is not defined?

while True :
    print ('Digite exit para sair')
    response = input ()
    if response == 'exit':
        sys.exit()
        print('Você digitou' + response + ',')

/data/data/org.qpython.qpy/files/bin/qpython3-android5.sh "/storage/emulated/0/qpython/exSair.py" && exit
e/emulated/0/qpython/exSair.py" && exit  <
Digite exit para sair
exit
Traceback (most recent call last):
  File "/storage/emulated/0/qpython/exSair.py", line 5, in <module>
    sys.exit()
NameError: name 'sys' is not defined
1|u0_a266@jflte:/ $
  • It’s not easier to test the case that response is not equal to 'exit' and leave without sys.exit()?

  • And must have missed the import sys at the beginning of the program

  • And learn how to format your question in Sopt.

  • Vlw. Thank you, I’m learning and I’m new to the stack.

  • This is @Ismaeldossantoscardoso! Welcome to Stack Overflow in English (Sopt). Check out this link: https://answall.com/tour

1 answer

1


The module sys is not set at runtime as it has not been imported.

At the top of your code, add:

import sys

Documentation of import.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.