{"id":576,"date":"2011-07-28T07:17:22","date_gmt":"2011-07-28T07:17:22","guid":{"rendered":"https:\/\/fir3netwp.gmsrrpobkbd.com\/2011\/07\/28\/python-temperature-convertor\/"},"modified":"2021-07-24T18:29:10","modified_gmt":"2021-07-24T18:29:10","slug":"python-temperature-convertor","status":"publish","type":"post","link":"https:\/\/www.fir3net.com\/Programming\/Python\/python-temperature-convertor.html","title":{"rendered":"Python – Temperature Convertor"},"content":{"rendered":"
Below is a small script to convert temperatures between celcuis and fahrenheit (and vice versa). This article \/ script is meant as reference point rather than a full tutorial.<\/p>\n
#!\/usr\/bin\/python<\/p>\n
import sys<\/p>\n
def convert(t,fc):
if t == “2f”:
print (fc * 9) \/ 5 + 32,”Degress Fahrenheit”
elif t == “2c”:
print (fc – 32) \/ 9 * 5,”Degress Celcuis”<\/p>\n
def usage():
print ”’\\
Usage: convert-temp [TEMP] [TYPE]
This program coverts the temperatures celcius and fahrenheit.
Options include:
–version : Prints the version number
–help : Display this help<\/p>\n
Examples:
convert-temp 33 2f Convert to fahrenheit
convert-temp 80 2c Convert to celcuis”’
try:
if sys.argv[1].startswith(‘–‘):
option = sys.argv[1][2:]
# fetch sys.argv[1] but without the first two characters
if option == ‘version’:
print ‘Version 0.1’
elif option == ‘help’:
usage()
else:
print ‘Unknown option.’
sys.exit()
elif len(sys.argv) < 3:
print ‘Insufficient Parameters.’
else:
type = sys.argv[2]
temp = int(sys.argv[1])
convert(type,temp)
except:
usage()<\/p>\n","protected":false},"excerpt":{"rendered":"
Below is a small script to convert temperatures between celcuis and fahrenheit (and vice versa). This article \/ script is meant as reference point rather than a full tutorial. #!\/usr\/bin\/python import sys def convert(t,fc): if t == “2f”: print (fc * 9) \/ 5 + 32,”Degress Fahrenheit” elif t == “2c”: print (fc – 32) … Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"yoast_head":"\n