返回0的python公式[已关闭]

ac1kyiln  于 2022-12-05  发布在  Python
关注(0)|答案(2)|浏览(117)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答案。

这个问题是由一个打字错误或一个无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
4小时前关门了。
Improve this question
所以我有基本的公式设置接收数字,然后转换他们,但当运行程序转换公式不计算
第一个

3htmauhk

3htmauhk1#

尝试在对数据进行input之后计算结果,而不是在此之前

balp4ylt

balp4ylt2#

"我会怎么做"

def get_input():
    print ("How many U.S dollars can you afford to spend on your trip?: ")
    dollars = float(input())

    print("How many pounds of chocoloate will you be buying?:")
    pounds = float(input())

    print("What is the tempature in degrees Celsius on the European news?:")
    tempC = float(input())
    return [dollars, pounds, tempC]

def dollars_to_euros(dollars):
    return 0.95 * dollars

def pounds_to_kilograms(pounds):
    return pounds / 2.2

def tempC_to_tempF(tempC):
    return tempC * 9 / 5 + 32

globe = "\U0001F30D"

[dollars, pounds, tempC] = get_input()

#move formula calculation after receiving the input
euros = dollars_to_euros(dollars)
kilograms = pounds_to_kilograms(pounds)
tempF = tempC_to_tempF(tempC)

print ("ITINERARY NOTES")
print ("------------------------------------------------------")

print (globe + " you have {:.2f} euros to spend." .format(euros))
print (globe + " Plan to buy {:.2f} of chocolate for family and friends".format(kilograms))
print (globe + " The tempature in Europe is {} degrees F, So dress appropriately.".format(tempF))

对现有代码段进行最小更改以使其正常工作:

dollars = 0
pounds = 0
tempF = 0
tempC = 0
globe = "\U0001F30D"

print ("How many U.S dollars can you afford to spend on your trip?: ")
dollars = float(input())

print("How many pounds of chocoloate will you be buying?:")
pounds = float(input())

print("What is the tempature in degrees Celsius on the European news?:")
tempC = float(input())

#move formula calculation after receiving the input
euros = dollars*.95
kilograms = pounds/2.2
tempF = tempC* 9/5+32 

print ("ITINERARY NOTES")
print ("------------------------------------------------------")

print (globe + " you have {:.2f} euros to spend." .format(euros))
print (globe + " Plan to buy {:.2f} of chocolate for family and friends".format(kilograms))
print (globe + " The tempature in Europe is {} degrees F, So dress appropriately.".format(tempF))

相关问题