def main():

celsius = float(input("What is the Celsius temperature? ")
fahrenheit = (9/5) * celsius + 32
print ("The temperature is ", fahrenheit, " degrees Fahrenheit.")

main()

error output:
Syntax Error:(line 8) fahrenheit = (9/5) * celsius + 32

This makes perfect sense to me. How can i fix this error?

Dani AI

Generated

The immediate cause of the SyntaxError is a missing closing parenthesis on the previous line — spotted that. Python will often flag the next line when a previous line leaves an open parenthesis or quote, so the error message points at the formula line even though the real problem is earlier. Fix the unmatched parenthesis and make sure the lines inside def main(): are actually indented.

Two related gotchas to be aware of, since they come up in this thread: first, integer vs. floating-point division depends on the Python version. As and noted, Python 2 will perform integer division when both operands are integers (which can silently truncate your result), while Python 3 uses true floating-point division with /. To make behavior explicit and portable, use floating-point literals or enable true-division in Python 2 with the appropriate future import. Second, input/print behave differently between 2.x and 3.x — if the code is being run under the other major version you may see surprising behavior.

Quick troubleshooting checklist:

  • Fix the missing parenthesis and re-run.
  • Verify function body indentation (4 spaces or a tab consistently).
  • Run python -m py_compile yourfile.py to get a clear syntax check.
  • Test pieces interactively (evaluate the input conversion, then the arithmetic) to isolate problems.
  • Use an editor that highlights matching parentheses and shows line numbers.

These small checks usually resolve the error and prevent related surprises from version differences.

Recommended Answers

All 4 Replies

a ')' at the end of line 1 is missing:

celsius = float(input("What is the Celsius temperature? "))
commented: sharp eye +14

Also, python is going to round (9/5) to 2 since these are integers. Get in the habit of using floats: (9.0/5.0)

Looks ike you are using Python3, so '/' will be floating point division and '//' an integer division. You can always test drive it ...

Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 2/3
0.6666666666666666
>>> 2//3
0
>>> 

I think it's time for me to start using Python3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.