Error: invalid syntax python

Asked

Viewed 122 times

-3

Good evening Personal am beginner in Python.Ai when the code appears the if ano=0:
Syntaxerror: invalid syntax

import requests 
from bs4 import BeautifulSoup

t=input('Digite o Nome do Filme:')
ano=int(input('Digite o Ano do Filme:')

if ano==0:
 req=requests.get('https://www.themoviedb.org/search?query='+t+'&language=pt-BR')) 
 bs=BeautifulSoup(req.text, 'lxml') 
 print(bs.find_all('img')) 
else:
 req=requests.get(req=requests.get('https://www.themoviedb.org/search?query='+t+'%20y%3A'+str(ano)+'&language=pt-BR'))) 
 bs=BeautifulSoup(req.text, 'lxml') 
 print(bs.find_all('img'))

I made the changes continue the same mistake.

  • 1

    Use: str(year) in concatenation. Troque req=requests.get(str('https://www.themoviedb.org/search?query='+t+'%20y%3A'+ano+'&language=en-BR')) by req=requests.get('https://www.themoviedb.org/search?query='+t+'%20y%3A'+str(year)+'&language=en-BR')

  • gave error if ano==0: Syntaxerror: invalid syntax

  • 1

    @Jacksuelsoaroarraga I reversed the question because the website format does not contain changes that invalidate the answers are made. Because even the AR (Author of the Answer) striving to solve your problem, if you modify the question the AR runs the risk of being negative even solving part of your problem. Use the comments below the answers to ask for clarifications and updates of the answers. Any questions do our [tour]. If you need to ask a new question, [Ask], and if you need to ask this question as a reference.

1 answer

1

Jacksuel,

On the line you order the year, missing close one parentheses:

ano=int(input('Digite o Ano do Filme:'))

After in the get of your zero year if, you have closed two parentheses, you need to remove one:

req=requests.get('https://www.themoviedb.org/search?query='+t+'&language=pt-BR')

Finally, in the get of your LSE, you again closed an extra parenthesis, you need to remove one here too, but in addition to this syntax error, you also wrote twice the req=request.get, including one within the other, correct as follows:

req=requests.get('https://www.themoviedb.org/search?query='+t+'%20y%3A'+str(ano)+'&language=pt-BR')

Correcting all these points, your code should be more or less as follows:

import requests 
from bs4 import BeautifulSoup

t=input('Digite o Nome do Filme:')
ano=int(input('Digite o Ano do Filme:'))

if ano==1:
  req=requests.get('https://www.themoviedb.org/search?query='+t+'&language=pt-BR')
  bs=BeautifulSoup(req.text, 'lxml') 
  print(bs.find_all('img')) 
else:
  req=requests.get('https://www.themoviedb.org/search?query='+t+'%20y%3A'+str(ano)+'&language=pt-BR')
  bs=BeautifulSoup(req.text, 'lxml') 
  print(bs.find_all('img'))

Be careful with the Python spaces, when you corrected the errors I mentioned you gave a space before the IF, this will also generate exceptions.

  • Now changed the error to Indentationerror: Unexpected indent

  • Yes, by your editing you broke the indentation of the code when you made the corrections.

  • Jacksuel, I made an edit on the information, be careful with the spaces and tabs in Python.

  • recommend some video lesson a document that explains?

  • Oops, man, I never took his courses, but I hear SUPER speak, and he has Python classes: https://www.youtube.com/user/cursosemvideo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.