1
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

3
  • the input from the user is considered a string, therefore converting it to an int should work OK. Can you please give the rest of the output regarding the error. Commented Jun 19, 2013 at 18:35
  • Mostly this error is seen when you try to concatenate a string and an integer: for e.g : '1' + 1 --> TypeError: Can't convert 'int' object to str implicitly, so check your code for such mistakes. Commented Jun 19, 2013 at 18:41
  • print (today) sql = ("INSERT INTO cafe () VALUES ('"+nome+"','"+nota+"','"+data+"')") cursor.execute(sql) cursor.commit() geraMenu() this is the rest Commented Jun 19, 2013 at 19:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey jedwards can you send me an email? I think its more easy send you all my program and you look all. Please, if you have time. [email protected]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.