[英]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...可能作为输入,您输入了无法转换为 int 类型的字符串值(在您的情况下为空字符串 - 您按下了
Enter
),它只接受 1,2,10,15,-1 等数字...
Solved, i've only changed the arg:已解决,我只更改了 arg:
keyboard.is_pressed
to到
keyboard.read_key
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.