0

This function converts celsius to fahrenheit

def celsius_to_fahrenheit (ctemp):
        temp_convert_to_fahr=int((ctemp+32)*1.8)

This function prints the celsius to fahrenheit table

def print_celsius_to_fahrenheit_conversion_table(min,max):
    print("Celsius\tFahrenheit")
    print("------------------")
    for num  in range (min,max):
            tempc=num
            tempf= celsius_to_fahrenheit(tempc)
            print(tempc,"\t",tempf)

This function converts from fahrenheit to celsius

def fahrenheit_to_celsius(tempf):
    f_to_c=int((tempf-32)/1.8)

This function prints the fahrenheit to celsius table

def print_fahrenheit_to_celsius_conversion_table(min,max):
    print("Fahrenheit\tCelsius")
    print("------------------")
    for num in range (min,max):
            tempf=num
            tempc= fahrenheit_to_celsius(tempf)
            print(tempf,"\t",tempc)
print()
print_celsius_to_fahrenheit_conversion_table(0,11)
print()
print_fahrenheit_to_celsius_conversion_table(32,41)

Every time I run this, my column that is being converted shows up as "none", any help as to what is wrong?

1
  • Open and shut case, thanks guys, that was so simple I'm a little embarrassed. Commented Mar 27, 2016 at 10:56

3 Answers 3

2

You are just assigning variables in your functions. You aren't returning anything. Just change f_to_c= and temp_convert_to_fahr= to return:

def celsius_to_fahrenheit (ctemp):
    return int((ctemp+32)*1.8)

def fahrenheit_to_celsius(tempf):
    return int((tempf-32)/1.8)

Since you don't return anything explicitly, the functions return None implicitly.

Sign up to request clarification or add additional context in comments.

Comments

0

When you want to get the value from a function you need to return the value from the function explicitly, otherwise Python automatically does return None.

Here's the corrected functions:

def celsius_to_fahrenheit (ctemp):
    temp_convert_to_fahr=int((ctemp+32)*1.8)
    return temp_convert_to_fahr

def fahrenheit_to_celsius(tempf):
    f_to_c=int((tempf-32)/1.8)
    return f_to_c

Comments

0

missing return statements in the functions

def celsius_to_fahrenheit (ctemp):
    temp_convert_to_fahr=int((ctemp+32)*1.8)
    return temp_convert_to_fahr

def fahrenheit_to_celsius(tempf):
        f_to_c=int((tempf-32)/1.8)
       return f_to_c

or

 def celsius_to_fahrenheit (ctemp):
        return int((ctemp+32)*1.8)  
def fahrenheit_to_celsius(tempf):
       return int((tempf-32)/1.8)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.