Python Forum
Importing a temperature converting module - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Importing a temperature converting module (/thread-6246.html)



Importing a temperature converting module - RedSkeleton007 - Nov-12-2017

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 fahrenheit
And 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.


RE: Importing a temperature converting module - buran - Nov-12-2017

It is because of While. it should be while.
Also, next time, please, post the entire traceback that you get. We need to see the whole thing. Do not just give us the last line. Take a time to read What to include in a post


RE: Importing a temperature converting module - sparkz_alot - Nov-12-2017

Also you are missing a closing quote on line 11. Why are you concatenating that line?