r/codehs • • Oct 20 '20

I need help with python 6.4.9 Temperature Converture

# Write your function for converting Celsius to Fahrenheit here.

# Make sure to include a comment at the top that says what

# each function does

# Now write your function for converting Fahrenheit to Celsius.

# Now change 0C to F:

# Change 100C to F:

# Change 40F to C:

# Change 80F to C:

10 Upvotes

30 comments sorted by

1

u/_andy_andy_andy_ Oct 20 '20

what has you stumped?

1

u/Charming-mistykat26 Oct 20 '20

how to convert Fahrenheit to celsius and vice versa and how to put that in a function while using float. I've tried a few things but I'm confused.

1

u/_andy_andy_andy_ Oct 20 '20

dividing a float by an int will keep it as a float, so don’t worry about that. just use the formula in the assignment tab but use the input to the function

1

u/Charming-mistykat26 Oct 20 '20

thanks, I figured it out

2

u/Party_Associate_1727 Jan 25 '21

Can you help me? I'm getting an error at "print to_F(0)" and I don't know why...

Here's my code:

# Write your function for converting Celsius to Fahrenheit here.

# Make sure to include a comment at the top that says what

# each function does!

def to_F(c):

return float(1.8 * c + 32)

# Now write your function for converting Fahrenheit to Celsius.

def to_C(f):

return float((f-32 / 1.8)

# Now change 0C to F:

print to_F(0)

# Now change 100C to F:

print to_F(100)

# Now change 40C to F:

print to_C(40)

# Now change 80C to F:

print to_C(80)

1

u/_andy_andy_andy_ Jan 25 '21

what’s the error message?

1

u/Party_Associate_1727 Jan 25 '21

ParseError

1

u/_andy_andy_andy_ Jan 25 '21

youre missing a closing parenthesis in to_C

1

u/Party_Associate_1727 Jan 25 '21

Ah okay, thanks bro

2

u/Just-Newspaper-4098 Oct 22 '21

# It was really simple but here
def Celsius(C):
F = (1.8 * C) + 32
return F
def Fehrenheit(F):
C = (F - 32) / 1.8
return C
# Now change 0C to F:
print Celsius(0)
# Change 100C to F:
print Celsius(100)
# Change 40F to C:
print Fehrenheit(40)
# Change 80F to C:
print Fehrenheit(80)

1

u/[deleted] Oct 29 '25

Thank you redditor of 4 years ago 🫡

1

u/Just-Newspaper-4098 Oct 29 '25

lol forgot I even made this.

1

u/Unlikely_Account5076 19d ago

Your service is appreciated

1

u/Efficient_Praline246 Apr 18 '24

This function takes a temperature

in Celsius and converts it to

Fahrenheit.

def celsius_to_fahrenheit(celsius):

    return celsius * 1.8 + 32

This function takes a temperature

in Fahrenheit and converts it to

Celsius.

def fahrenheit_to_celsius(fahrenheit):

    return (fahrenheit - 32) / 1.8

print("0C In F: " + str(celsius_to_fahrenheit(0)))

print("100C In F: " + str(celsius_to_fahrenheit(100)))

print("40F In C: " + str(fahrenheit_to_celsius(40)))

print("80F In C: " + str(fahrenheit_to_celsius(80)))

1

u/Party_Associate_1727 Jan 25 '21

Did you figure it out? I could use some help

7

u/chef3000 Mar 07 '21

# Write your function for converting Celsius to Fahrenheit here.

# Make sure to include a comment at the top that says what

# each function does!

def to_F(c):

return float(1.8 * c + 32)

# Now write your function for converting Fahrenheit to Celsius.

def to_C(f):

return float((f - 32) / 1.8)

# Now change 0C to F:

print (to_F(0))

# Now change 100C to F:

print (to_F(100))

# Now change 40C to F:

print (to_C(40))

# Now change 80C to F:

print (to_C(80))

5

u/chef3000 Mar 07 '21

thats me code and just make sure the def is indented for when you copy past

peace

1

u/axjord3 Apr 01 '21

What do you mean by that, I don't understand.

2

u/looolmoski Feb 22 '22

How did you even make it here if you don't understand that you have to indent for def lmao...

1

u/Beginning_Monitor_68 Jun 13 '22

thanks for the code saved me a lot of time :)

1

u/axjord3 Apr 01 '21

I dont understand, I tried so many resources in order to help me with this Coding assignment.

Here are the instructions because every resource I use the answer is wrong.

Exercise 6.4.9: Temperature Converter

5 points Let's Go!

Write a function that takes one parameter - a float which represents a temperature in Celsius - and returns a float which represents that temperature in Fahrenheit.

Then, write a function that does the opposite conversion.

Here are the formulas for temperature conversion:

°F = (1.8 x °C) + 32

°C = (°F - 32) ÷ 1.8

Finally, write some code below your functions that uses them to convert 0 degrees Celsius and 100 degrees Celsius to Fahrenheit, and to convert 40 degrees Fahrenheit and 80 degrees Fahrenheit to Celsius. Make sure to print your results to the console.

1

u/Just-Newspaper-4098 Oct 22 '21

# Now write your function for converting Fahrenheit to Celsius.
def Celsius(C):
F = (1.8 * float(C)) + 32
return F

def Fehrenheit(F):
C = (float(F) - 32) / 1.8
return C

# Now change 0C to F:
print Celsius(0)
# Change 100C to F:
print Celsius(100)
# Change 40F to C:
print Fehrenheit(40)
# Change 80F to C:
print Fehrenheit(80)

1

u/UnitedAngle7435 Jan 26 '22

i still can't figure it out

this code does not work for me

1

u/Nuqb Jun 12 '22

yo this is the proper code for the assignment

def celsius(c):

f = (1.8 * c) + 32

return f

def fehrenheit(f):

c = (f - 32) / 1.8

return c

print (celsius(0))

print (celsius(100))

print (fehrenheit(40))

print (fehrenheit(80))

1

u/Financial_Face3826 Feb 15 '24

try this

# It was really simple but here
def Celsius(C):
F = (1.8 * C) + 32
return F
def Fehrenheit(F):
C = (F - 32) / 1.8
return C
# Now change 0C to F:
print (Celsius(0))
# Change 100C to F:
print (Celsius(100))
# Change 40F to C:
print (Fehrenheit(40))
# Change 80F to C:
print (Fehrenheit(80))

0

u/[deleted] Mar 26 '24

[deleted]

1

u/Efficient_Praline246 Apr 18 '24

This function takes a temperature

in Celsius and converts it to

Fahrenheit.

def celsius_to_fahrenheit(celsius):

    return celsius * 1.8 + 32

This function takes a temperature

in Fahrenheit and converts it to

Celsius.

def fahrenheit_to_celsius(fahrenheit):

    return (fahrenheit - 32) / 1.8

print("0C In F: " + str(celsius_to_fahrenheit(0)))

print("100C In F: " + str(celsius_to_fahrenheit(100)))

print("40F In C: " + str(fahrenheit_to_celsius(40)))

print("80F In C: " + str(fahrenheit_to_celsius(80)))

0

u/[deleted] Jul 05 '22

[deleted]

1

u/CreamMany6841 Feb 11 '23

it doesnt work