0

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?

7
Contributors
7
Replies
8
Views
12 Years
Discussion Span
Last Post by Duskic
0

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) )
0

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

-1

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()

Edited by kjock002: n/a

0

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.

Edited by Gribouillis: n/a

0

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)

Edited by Foca1or: n/a

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.