简体   繁体   中英

Why i'm getting the following error? ValueError: invalid literal for int() with base 10: ''

Here is the code

from time import sleep
import keyboard

# Condição de partida da máquina
while True:
    if keyboard.is_pressed('ENTER'):
        print('\nProcessando...\n')
        sleep(2)
        break

print('\nRETIRE O CARTÃO.')

opcao = int(input('SELECIONE UMA OPÇÃO:\n'
                  '\033[32m[1] DEPÓSITO\033[m\n'
                  '\033[32m[2] SAQUE\033[m\n'
                  '\033[32m[3] SALDO/EXTRATO\033[m\n'
                  '\033[32m[4] POUPANÇA\033[m\n'))

and now, the error:

Traceback (most recent call last):
  File "-", line 18, in <module>
    opcao = int(input('SELECIONE UMA OPÇÃO:\n'
ValueError: invalid literal for int() with base 10: ''

I can't find what's wrong with the code... Someone can help me? I've already tried to rewrite the code, but this problem is really killing me...

Probably as input you entered string value which can't be casted to int type(in your case empty string - you pressed Enter ), it only accepts number like 1,2,10,15,-1, etc...

Solved, i've only changed the arg:

keyboard.is_pressed

to

keyboard.read_key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM