# convert2.py
# PPython Monty
# Lab 2 Ch 2, PE 4
# A program to convert temperatures from Celsius to Fahrenheit and
# vice versa
def main():
# description of program
print("This program converts Celsius temperatures to Fahrenheit and")
print("vice versa.")
conversion = ("C")
n = eval(input("How many temperatures would you like converted?: "))
for i in range(n):
conversion = input("Enter 'F' to convert to Fahrenheit, 'C' to convert to Celsius or a number: ")
if conversion == ("F"):
F = 9/5 * C + 32
elif conversion == "C":
C = (F - 32) * 5/9
else:
C = (F - 32) * 5/9
main()
Basically I'm suppose to ask the user to input how many times they want to run the loop, then after they input a number, depending on if they enter C or F, the number they input next would be converted to Celsius or Fahrenheit.
I'm a noob at this, so I don't know exactly what I am doing wrong here. The code looks right and runs, but as soon as I enter F or C, it crashes. Also once I fix that problem, I'm not even sure if the code would work once I enter a number to get converted.
The thing is I keep getting errors no matter what I do. If I enter C or F, I get
"UnboundLocalError: local variable 'F' referenced before assignment"
or
UnboundLocalError: local variable 'C' referenced before assignment