Python Forum
Question re: running code in Editor (i.e. Atom) vs Python interpreter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Question re: running code in Editor (i.e. Atom) vs Python interpreter (/thread-27971.html)



Question re: running code in Editor (i.e. Atom) vs Python interpreter - rok - Jun-29-2020

Python3

New coder

Prompt:

Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.

Question:

When I attempted to solve the following problem in the interpreter, it results in the following:

ctemp = input('Enter Celsius Temperature') \
... ftemp = float(ctemp) * (9 / 5) + 32 \
File "<stdin>", line 2
ftemp = float(ctemp) * (9 / 5) + 32 \
^
SyntaxError: invalid syntax


However, when I enter the same code in the Atom editor, no error occurs and the program runs with the correct answer.

My understanding is that aside from the pro's vs con's between using an editor vs. the interpreter, the Python rules (including syntax) are the same between an editor such as Atom and the interpreter.

Can you please examine my code to explain what I've missed?

Thank you everyone in advance for your help.


RE: Question re: running code in Editor (i.e. Atom) vs Python interpreter - bowlofred - Jun-29-2020

Why do you have backslashes at the end of your lines? They look like complete lines, so I'm not sure what you're trying to accomplish with them.

Running a program in the interactive prompt that asks for input can be tricky. Because the input will run immediately and ask you for input, and it can be hard to tell if it's time to type an input answer, or if you're still entering code. At first, you might try it without the input and just put in a number. Then add the input back later when everything is working or you're not in the interactive prompt.


RE: Question re: running code in Editor (i.e. Atom) vs Python interpreter - rok - Jun-29-2020

I put the backslash so that it will not execute immediately.

Thank you for your help bowlofred.

This was my first post here in the forums. Going forward I will be sure to utilize the python tags.

Any additional input is appreciated.

Thank you everyone. This forum is great!


RE: Question re: running code in Editor (i.e. Atom) vs Python interpreter - bowlofred - Jun-29-2020

I think the backslashes are interfering with what you're trying to do.

I'd recommend that you type it out into a file with an editor, then run the full program separately. It also helps when you're asking questions about it because everyone is certain exactly what the program is.