0

Need help with how to run this program. Spent three days learning Python3 basics and still struggling very much so

After completing the Python3 tutorial and playing around with many of the "try it yourself" options I was completely confused on how to even start writing code on my own, let alone reading other's code. I googled a temperature conversion program but it is not working for me, it says "SyntaxError: invalid syntax". I don't understand. Here is the code: temp = input("Input the temperature you like to convert? (e.g., 45F, 102C etc.) : ") degree = int(temp[:-1]) i_convention = temp[-1] if i_convention.upper() == "C": result = int(round((9 * degree) / 5 + 32)) o_convention = "Fahrenheit" elif i_convention.upper() == "F": result = int(round((degree - 32) * 5 / 9)) o_convention = "Celsius" else: print("Input proper convention.") quit() print("The temperature in", o_convention, "is", result, "degrees.")

25th Mar 2018, 5:49 PM
Joseph Bavone
Joseph Bavone - avatar
5 Answers
0
I figured out what I was doing wrong! I was running the code in the Python shell. I am not supposed to do that and I still do not know why. This is all I did: 1. I opened up IDLE (Python 3.6 64 bit) 2. I clicked on File-->New File 3. I copied and pasted the code in this new page (new file) and successfully ran the code.
25th Mar 2018, 6:53 PM
Joseph Bavone
Joseph Bavone - avatar
+ 5
It works Are you sure you worked with python3? https://code.sololearn.com/cwIDkCmYC3tc/?ref=app
25th Mar 2018, 6:08 PM
Oma Falk
Oma Falk - avatar
+ 2
The code as you have it posted here works fine with no issues as far as I can see. If you copied and pasted the code into the playground or an editor/IDE etc you may have also picked up some invisible characters along with the code causing the issue. Try typing it out making sure to use proper indentation etc.
25th Mar 2018, 6:04 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Perhaps it did catch some invisible characters. hmmm ill try to type it out. thanks so much!
25th Mar 2018, 6:06 PM
Joseph Bavone
Joseph Bavone - avatar
0
I am still having problems here. I know for a fact I am making a simple error. Unfortunately, even after dedicating all the time to finish Python3 tutorial I am unable to understand my little mistake. I tried figuring out what I am doing wrong. Here are a couple error messages that have popped up (not to mention several others): 75F : Traceback (most recent call last): File "..\Playground\", line 4, in <module> degree = int(temp[:-1]) ValueError: invalid literal for int() with base 10: '' Input the temperature you like to convert? (e.g., 45F, 102C etc.) : Traceback (most recent call last): File "..\Playground\", line 4, in <module> degree = int(temp[:-1]) ValueError: invalid literal for int() with base 10: ''
25th Mar 2018, 6:15 PM
Joseph Bavone
Joseph Bavone - avatar