Temperature Conversion v0.2

I just learned how to implement basic command-line argument with Python. Hence, I would like to incoporate this feature in the previous Temperature Conversion program.

# convertc2f.py
# Version: 0.2
# A program to convert Celsius temps to Fahrenheit
# Date: 4/13/06
# by: S. San (Kenno)

import sys

if (len(sys.argv) == 2):
    celsius = int(sys.argv[1])
else:
    celsius = int(input("What is the Celsius temperature? "))

fahrenheit = 9.0 / 5.0 * celsius + 32
print "The temparature is ", fahrenheit, " degrees Fahrenheit."

Example with the command line argument:

$ python convertc2f.py 100
The temparature is 212.0 degrees Fahrenheit.

Without any argument:

$ python convertc2f.py
What is the Celsius temperature? 100
The temparature is 212.0 degrees Fahrenheit.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: