1

The given function is:

def Temp_Conv(Temp_in, case):

Where Temp_in is an integer, and case is a string. Case can be inputted as 'C2F' (celsius to fahrenheit) or 'F2C' (fahrenheit to celsius). I only need to convert celsius to fahrenheit, so when case=='C2F', then I will apply the conversion formula. However, if case=='F2C' then the return must be 'Wrong case value'. This is how I set up my program:

def Temp_Conv(Temp_in,case):
    if case=='C2F':
        return ((Temp_in*(9/5)) + 32)
    if case=='F2C'
        return 'Wrong case value'

Is this the correct way to do this?

Stefan
  • 37
  • 5
  • 1
    Looks like what you described is what you implemented. Is there an issue when you run it? – Chris Loonam May 16 '20 at 05:03
  • Run the program and you will get to know whether it's right or wrong – bigbounty May 16 '20 at 05:04
  • Unfortunately i'm unable to run the program because I was given no input values, just that following information for an assignment. Is there a way I can make my own input values? – Stefan May 16 '20 at 05:08
  • `Temp_Conv` is a function, call the function passing the relevant info to the function. `result = Temp_Conv(20, "C2F")` – bigbounty May 16 '20 at 05:10

1 Answers1

2

To test if your funciton works.

def Temp_Conv(Temp_in,case):
    if case=='C2F':
        return ((Temp_in*(9/5)) + 32)
    if case=='F2C':
        return 'Wrong case value'

case = input("please enter a case: ")
temp = 30
print(Temp_Conv(temp, case))

This should run the function to see if it works or not.

Prab
  • 464
  • 3
  • 13
  • Whenever I try to run this, the output is 'C2F' and the program keeps looping infinitely. Strange, do you know why? – Stefan May 16 '20 at 06:23
  • Nevermind, I tried typing case=input('C2F') because I thought that's what you meant, but I entered "please enter a case" and then afterwards I typed 'C2F' and the output was 86, so it worked! Thank you so much. – Stefan May 16 '20 at 06:26