Python Forum
Question re: running code in Editor (i.e. Atom) vs Python interpreter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question re: running code in Editor (i.e. Atom) vs Python interpreter
#1
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.
Reply
#2
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.
Reply
#3
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!
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 547 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 345 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 876 Nov-15-2023, 06:56 PM
Last Post: jst
  the order of running code in a decorator function akbarza 2 480 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Mac default python interpreter Viewpoint8455 2 874 Oct-13-2022, 06:25 AM
Last Post: perfringo
  How to expand and collapse individual parts of the code in Atom Lora 2 1,104 Oct-06-2022, 07:32 AM
Last Post: Lora
  Folding in ATOM XavierPlatinum 5 1,169 Sep-11-2022, 09:21 PM
Last Post: XavierPlatinum
  Code running many times nad not just one? korenron 4 1,326 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,548 Jul-01-2022, 02:51 PM
Last Post: maiya
  Sublime Text Editor not recognizing Python elroberto 5 2,802 Jun-13-2022, 04:00 PM
Last Post: rob101

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020