if abs(celsius % 1) < 0.001 # Or whatever threshold you want:
print("The temperature in celsius is: {:d}°.".format(int(celsius//1)))
else:
print("The temperature in celsius is: {:.2f}°.".format(celsius))
temp = float(input(" Fahrenheit temperature: "))
celsius = float((5/9)*(temp - 32))
if (celsius % 1 == 0):
print("The temperature in celsius is: {}°.".format(celsius))
else:
print("The temperature in celsius is: {:.2f}°.".format(celsius))
您需要单独执行此操作,因为与50“足够接近”以显示为50的内容是特定于应用程序的。你知道吗
您可以尝试以下方法:
if
条件检查您是否有整数。你知道吗试试这个:
这将打印10,其中常规打印将返回10.0
可能有更好的方法,但这很管用;)
相关问题 更多 >
编程相关推荐