这个代码就是一个摄氏度和华摄氏度相互转换的代码,代码没问题,如何将摄氏度和华摄氏度转换部分分别定义为两个函数,来运行,麻烦看一下,给一个修改后的代码,谢谢
print("Press1:Fahrenheit→centigrade")
print("Press2:centigrade→Fahrenheit")
temp=input("Please enter the function you want to select:")
guess=int(temp)
if guess==1 :
temp=input("Please enter the Fahrenheit to be converted:")
F=int(temp)
C=(F-32)/1.8
print("Fahrenheit:"+str(F)+"F = centigrade:"+str(C)+"℃")
elif guess==2 :
temp=input("Please enter the centigrade to be converted:")
C=int(temp)
F=C*1.8+32
print("centigrade:"+str(C)+"℃ = Fahrenheit:"+str(F)+"F")
else :
print("Please check your input!")
print("Press1:Fahrenheit→centigrade")
print("Press2:centigrade→Fahrenheit")
temp = input("Please enter the function you want to select:")
guess = int(temp)
def convertFah_Centi(F):
C = (F - 32) / 1.8
print("Fahrenheit:" + str(F) + "F = centigrade:" + str(C) + "℃")
def convertCenti_Fah(C):
F = C * 1.8 + 32
print("centigrade:" + str(C) + "℃ = Fahrenheit:" + str(F) + "F")
if guess == 1:
temp = input("Please enter the Fahrenheit to be converted:")
F = int(temp)
# C = (F - 32) / 1.8
# print("Fahrenheit:" + str(F) + "F = centigrade:" + str(C) + "℃")
convertFah_Centi(F)
elif guess == 2:
temp = input("Please enter the centigrade to be converted:")
C = int(temp)
# F = C * 1.8 + 32
# print("centigrade:" + str(C) + "℃ = Fahrenheit:" + str(F) + "F")
convertCenti_Fah(C)
else:
print("Please check your input!")