GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Apr-2006, 23:00
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,576
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Python script: Celsius to Fahrenheit


I wrote a few little scripts to showcase how Python works for simple problems. They don't do anything major; they're just to showcase Python syntax in action so you can compare it to other languages.

The first program is a simple temperature convertor, from Celsius to Fahrenheit. Feel free to use and abuse this script if you want; just copy it and save it with a .py extension. Run it however you run a Python script, normally calling python foo.py on the command line.
Python Code:
##########################################################
#Create a chart of fahrenheit to celsius conversions from 0 to 100 degrees.
#Author:  Cody Jackson
#Date:  4/10/06
##########################################################

def fahrenheit(celsius):
    """Converts celsius temperature to fahrenheit"""
    
    fahr = (9.0/5.0)*celsius + 32
    return fahr

#---Create table
print "Celsius | Fahrenheit\n"  #header

for temp_c in range (0, 101):
    temp_f = fahrenheit(temp_c)
    print temp_c, " | %.1f\n" % temp_f
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues converting Fahrenheit to celsius Skampy C++ Forum 7 25-Feb-2006 09:04
Re: Beginning Python Tutorial (Part 9) crystalattice Python Forum 0 19-Feb-2006 02:04
First prog, using functions that pass values... boousaf C Programming Language 2 27-Sep-2005 17:10
Re: Beginning Python Tutorial (Part 2) crystalattice Python Forum 2 31-Jul-2005 13:25
Two virtual hosts, cgi script behaves differently on each blimbo Apache Web Server Forum 0 04-Aug-2004 10:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:21.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.