'''
#Temperature Converter
#Author: Coleton Ishmael
#Class: ICS 3U
#Date: 10/29/2015
'''
我需要创建一个程序来计算三种不同系统的温度,即摄氏温度,开尔温温度和华氏温度。我在下面的代码中遇到了一些问题,因为它并没有按照我的想法运行。看看下面,我所遇到的问题列在代码结束的底部!
#Fahrenheit to Celsuis and Kelvin
typeofconversion= (raw_input(" Would you like to convert Fahrenheit (type F), Celsius (type C) or Kelvin (type K)?"))
if typeofconversion== " F":
statement= (raw_input( " What is the temperature in Fahrenheit?"))
fcconversion= (int(statement)-32)*5.0/9
fkconversion= (int(statement)-32)/1.8000 +273.15
print " In Celsuis, that is:"
print round(fcconversion,2)
print " In Kelvin, that is:"
print round (fkconversion,2)
if typeofconversion== " C":
#Celsius to Fahrenheit and Kelvin
statement= (raw_input( " What is the temperature in Celsuis?"))
cfconversion= (int(statement) *9) / 5 + 32
ckconversion=(int(statement)+273)
print " In Fahrenheit, that is:"
print round(cfconversion,2)
print " In Kelvin, that is:"
print round(ckconversion,2)
elif typeofconversion== " K":
#Kelvin to Celsius and Fahrenheit
statement= (raw_input( " What is the temperature in Kelvin?"))
kcconversion= (int(statement) *9) / 5 + 32
kfconversion=(int(statement)- 273.15)* 1.8000+ 32.00
print " In Celsius that is:"
print round(kcconversion,2)
print "In Fahrenheit that is:"
print round(kfconversion,2)
#Conversions defined
def fcconversion (fcconversion):
result=""
'''
Main Program
'''
# Celsius to Fahrenheit, and Kelvin Loop
for i in range(2):
typeofconversion= (raw_input(" Would you like to convert Fahrenheit (type F), Celsius (type C) or Kelvin (type K)?"))
if typeofconversion== " F":
statement= (raw_input( " What is the temperature in Fahrenheit?"))
fcconversion=(int(statement)-32)*5.0/9
fkconversion=(int(statement)-32)/1.8000 +273.15
print " In Celsuis, that is:"
print round(fcconversion,2)
print " In Kelvin, that is:"
print round (fkconversion,2)
if typeofconversion==" C":
statement= (raw_input( " What is the temperature in Celsuis?"))
cfconversion=(int(statement) *9) / 5 + 32
ckconversion=(int(statement)+273)
print " In Fahrenheit, that is:"
print round(cfconversion,2)
print " In Kelvin, that is:"
print round(ckconversion,2)
我在尝试为代码的Celsius部分执行循环时遇到错误。这是说fcconversion没有定义它。我想知道我的代码有什么问题!
答案 0 :(得分:0)
for i in range(3):
typeofconversion= (raw_input(" Would you like to convert Fahrenheit (type F), Celsius (type C) or Kelvin (type K)?"))
if typeofconversion== " F":
statement= (raw_input( " What is the temperature in Fahrenheit?"))
fcconversion=(int(statement)-32)*5.0/9
fkconversion=(int(statement)-32)/1.8000 +273.15
print " In Celsuis, that is:"
print round(fcconversion,2)
print " In Kelvin, that is:"
print round (fkconversion,2)
#Fahrenheit to Celsius and Kelvin Loop
if typeofconversion==" C":
statement= (raw_input( " What is the temperature in Celsuis?"))
cfconversion=(int(statement) *9) / 5 + 32
ckconversion=(int(statement)+273)
print " In Fahrenheit, that is:"
print round(cfconversion,2)
print " In Kelvin, that is:"
print round(ckconversion,2)
#Kelvin to Celsius and Fahrenheit Loop
if typeofconversion== " K":
statement= (raw_input( " What is the temperature in Kelvin?"))
kcconversion= (int(statement) *9) / 5 + 32
kfconversion=(int(statement)- 273.15)* 1.8000+ 32.00
print " In Celsius that is:"
print round(kcconversion,2)
print "In Fahrenheit that is:"
print round(kfconversion,2)