I've been messin with python for little under a month now. I've come across one of these sample questions that make you think, stating to compute and print a table of Celsius temperatures and Fahrenheit equivalents ever 10 degrees... well i guess the main thing is i need help trying to make it print every 10 degrees... i can get it to compute it, but do you need a loop or something to do it?

I pulled that out of one of my Python snippets. It shows you how to use the for loop in steps of 10.

All you need to do is to rewrite the function to convert from Celsius to Fahrenheit ...

# define/create a function
# the indented lines are part of the function
def convertFahrenheit2Celsius(fahrenheit):
    celcius = 0.555 * (fahrenheit - 32)
    return celcius

print

# and use the function
# (make sure you define/create the function before you call it)
print "A Fahrenheit to Celcius table:"
# range is from -40 to < 220 in steps of 10
for tf in range(-40, 220, 10):
    print "%5.1fF = %5.1fC" % ( tf, convertFahrenheit2Celsius(tf) )

dude thanks a bunch... that helped me out big time cause i've been mulling at it for a while...

hi im actually doing the same thing for a lab in my programming class but im having such a hard time to make the table for celcius to fahrenheit. this is what i have so far and i need some help.

#convert.py
# A program to convert Celsius temps to Fahrenheit
# by: Susan Computewell

def main():
    celsius=input("What is the Celsius temperature?")
    fahrenheit=(9.0/5.0)* celsius + 32
    print "A Fahrenheit to Celsius table:"
    for i in range(0, 100, 10):
        print

main()

hi im actually doing the same thing for a lab in my programming class but im having such a hard time to make the table for celcius to fahrenheit. this is what i have so far and i need some help.

#convert.py
# A program to convert Celsius temps to Fahrenheit
# by: Susan Computewell

def main():
    celsius=input("What is the Celsius temperature?")
    fahrenheit=(9.0/5.0)* celsius + 32
    print "A Fahrenheit to Celsius table:"
    for i in range(0, 100, 10):
        print

main()

You should copy and paste the code that Vegaseat wrote above, and change the formula to get farenheit from celsius instead of celsius from farenheit.

I've got an assignment to print out a table of wind chills, the rows are windspeeds 0-50 on increments of 5 and the columns are temperatures from -20 to 60 in increments of 10. and i've been trying to alter Vegas's code to do this, and i'm just not comprehending it. If some one could put me on the right path, i'd truly appreciate it.
#if it helps to know what the equation is, t is temperature Fahrenheit, c is windspeed.
def windspeed(t,c):
windchill = 35.74 + 0.6215*t - 35.75(v**0.16) + 0.4275*t*(v**0.16)

Of course you are returning the windchill like vegaseat returns celcius?

I apologize for bringing up this old topic. The reason I am doing this is because I believe this line of code deserves to be here.

I just started playing with Python, and I found this line of code on Yahoo answers that solves the converting from Celsius to Fahrenheit and creating a table. Doing it in a very simple and effective way.

print '\n'.join( ['%3iC %5.1fF' % (c,1.8*c+32) for c in range(-40,110,10) ] )

What Vegaseat did also works, outpot looks even nicer, and it transforms Fahrenheit to Celsius.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.