'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...
Solution 1:[1]
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...
Solution 2:[2]
Solved, i've only changed the arg:
keyboard.is_pressed
to
keyboard.read_key
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Worldmaster |
| Solution 2 | Rodrigo Farah |
