Nov-12-2017, 04:57 AM
So I'm trying to learn how to import functions from a module. This one converts degrees fahrenheit to celsius, or degrees celsius to fahrenheit, depending on user input. Here's the module's code:
#!/usr/bin/env python3 #TemperatureModule.py def toCelsius(fahrenheit): """ Accepts degrees Fahrenheit (fahrenhit argument) Returns degrees Celsius """ celsius = (fahrenheit - 32) * 5/9 return celsius def toFahrenheit(celsius): """ Accepts degrees Celsius (celsius argument) Returns degrees fahrenheit """ fahrenheit = celsius * 9/5 + 32 return fahrenheitAnd here's the code of the .py file I'm trying to import the module into:
#!/usr/bin/env python3 #TemperatureModuleUser.py import TemperatureModule as temp def convertDegrees(F, C): getDegrees = float(input("Enter the number of degrees you wish to convert.")) round(getDegrees,2) degreeUnits = "" While degreeUnits != "F" and degreeUnits != "C": degreeUnits = input("Are those degrees in Fahrenheit or Celsius? + "(Enter F for Fahrenheit, or C for Celsius)") if(degreeUnits == F): F = temp.toCelsius(C) print(str(getDegrees) + " degrees Fahrenheit is equivalent to " + str(F) + " degrees Celsius.") elif(degreeUnits == C): C = temp.toFahrenheit(F) print(str(getDegrees) + " degrees Celsius is equivalent to " + str(C) + " degrees Fahrenheit.") else: print("Error. Enter F for Fahrenheit, or C for Celsius.") convertDegrees(F, C)Right now, the error is on line 9, saying that degreeUnits is invalid syntax. How can that be? I've declared that variable on line 8, right before the while loop statement.