Isaias20
Isaias20

Reputation: 33

Python sqlite3 error

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

appears this:

Can't convert 'int' object to str implicitly

Upvotes: 1

Views: 224

Answers (1)

jedwards
jedwards

Reputation: 30260

First, the code you provided "works" in Python 2.7 and 3.

A line number or stacktrace would be helpful, but assuming it's in the snippet you provided:

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

Here nota is an int.

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

The next line you're trying to cast it to a string without specifying how.

Something like:

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

should prevent the error.

That being said, the line still makes little sense. You shouldn't have to strip() a string representation of an integer.

What are you trying to accomplish with strip() and the if len(...) == 0 parts?

Edit: Lastly, I think you want raw_input() instead of input(), unless you're shadowing that somewhere too.

Upvotes: 1

Related Questions