syntax error in python

Asked

Viewed 214 times

-2

I’m trying to solve this code but at the time of running the syntax error on the first line.

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> segundos_str = input("por favor, entre com o número de segundos que deseja converter: ")
tota_segs = int(segundos_str)

horas = total_segs // 3600
segs_restantes = total_segs % 3600
minutos = segs_restantes // 60
segs_restantes_final = segs_restantes % 60

print(horas, "horas, ", minutos, "minutos e", segs_restantes_final, "segundos.")

erro de sintaxe pytoh

  • Try to paste the commands into the interpreter one at a time. There seems to be no syntax error in the first line. There must be some problem with an unprintable character at the end of the line. Looking at your screen, you can see that the second line prompt did not appear...

  • What it looks like is that you copied the code from somewhere and pasted it into the Python Shell. If it is, all this initial data is unnecessary in the file and breaks the syntax.

  • Thank you very much to all who have collaborated, I am very grateful.

2 answers

3

You didn’t write a Python program.

You copied everything that was on the interactive interpreter screen, and you’re trying to run it like a program.

Although the windows are similar, they are environments with purpose completely different.

The first statement of Python actually that is there, which could be the first line of your program is:

seconds_str = input("please... convert: ")

note that the characters >>> are also not part of what you type into a program - they are the indicator of "type your Python expression here", but in the interactive environment.

The suggestion, as it is in the comments, is to study Python in the interactive environment, until you have some idea of what you are doing. You copied and pasted the warning of the Python version as if it were a program, and are not understanding that this is not part of the language - you have to understand at least this before trying to make a program - the suggestion is that you look for some tutorials at the very beginning level - and practice in interactive mode.

  • Look at the photo he posted. He’s in the interactive environment. And it only has all the Python Shell code in its question because it probably gave Ctrl+C and Ctrl+V to show us. The error is in the variable total_segs that he wrote tota_seg by mistake on the second line of code.

  • 2

    enter Idle. Copy and paste what you see into the interactive environment into a file window. Go to "Run->Check Module". You have an image exactly the same as the image, with error window, and highlght in Python "7" 3.7

  • Jsbueno was exactly how you described I copied and pasted for you to see what was happening, but I really appreciate the help.

  • if that was the problem, mark this answer as accepted (the green checkpoint)

0


The error is not in the first line, but in the second. Its variable total_segs is misspelled in the second line. Is tota_segs.

This error will be evidenced from the third line of code, when you make a calculation using total_segs without having set it before because of the typo.

Always try to run one line at a time in the Shell. This helps to find the error.

Browser other questions tagged

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