I created these two scripts (c2f.py and f2c.py) converting an input value to fahrenheit or celsius depending what scripts you use and it works fine, but i created a third tempconversion.py file and just need help with how to ask for a new input integer and ask which temperature type they would like to convert to on this file, and then import the correct conversion file in order to insert the new input on the new file. I just need to know how to properly insert the new value into the imported file and function. the third picture showing tempconversion.py is the one that needs to be ran. tempconversion.py
CodePudding user response:
can you show your code here. attach a image of code or paste code
CodePudding user response:
If i understood you correctly, you are trying to pass the temperature value and type input and then run the function based on that input. In order to do that you need to pass your input as a parameter in the function
in your tempconversion.py file you should use basic input output instead of function to get input
import c2f, f2c
if __name__ == '__main__':
# getting temp value in integer
tempValue = int(input("Input a temperature to be converted : "))
# getting type
typeTemp = input("Convert to Fahrenheit(F) or Celcius(C)?: ")
if (typeTemp == 'F'):
print(c2f.c2f(tempValue))
elif (typeTemp == 'C'):
print(f2c.f2c(tempValue))
else:
print("invalid input")
and in f2c.py you should change it to this
def f2c(tempValue):
return ((tempValue - 32 ) * 5/9)
because in the tempconversion we already ask the user to input the value, we dont need to make user input it again. Also we should remove the name == 'main' because this file should just contain a function, we are not trying to run anything here
and in c2f.py
def c2f(tempValue):
return ((tempValue * 9/5) 32)