Python sqlite3

2024-04-27 15:14:57 发布

您现在位置:Python中文网/ 问答频道 /正文

def menuAdiciona():
    nome = input("Digite o nome de quem fez o cafe: ")
    nota = int(input("Que nota recebeu: "))

    if len(str(nome).strip()) == 0:
        menuAdiciona()

    if (nota) == 0:
        menuAdiciona()

    if nota < 0:
        nota = 0

显示如下:

Can't convert 'int' object to str implicitly


Tags: inputifcafedefdeintquenota
1条回答
网友
1楼 · 发布于 2024-04-27 15:14:57

首先,您提供的代码在Python2.7和3中“起作用”。在

行号或stacktrace会很有用,但假设它在您提供的代码段中:

nota = int(input("Que nota recebeu: "))

这里nota是一个int

^{pr2}$

下一行尝试将其转换为字符串而不指定如何转换。在

比如:

if len(("%d" % nota).strip()) == 0:

应该可以防止错误。在

尽管如此,这条线还是没有什么意义。你不应该strip()一个整数的字符串表示。在

你想用strip()if len(...) == 0部分来完成什么?在

编辑:最后,我认为你想要raw_input()而不是{},除非你也在某处隐藏它。在

相关问题 更多 >