如何根据约定在表达式和语句中使用空格?

我尝试提交此代码:

temperature = input("enter a tempereture as you wish: ")
convertion = int(temperature[:-1])
if temperature[-1] == "C":
    convertion = int((9 * convertion) / 5 + 32)
    temperature = str(convertion) + "F"
elif temperature[-1] == "F":
    convertion = int((5 * convertion) / 9 - 160/9)
    temperature = str(convertion) + "C"
print(temperature)

这样做的时候,我被告知我的写作没有遵循惯例。我读了https://www.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements,但仍然无法理解我的错误。我在哪里错了?

allcap 回答:如何根据约定在表达式和语句中使用空格?

似乎在此行的末尾:

convertion = int((5 * convertion) / 9 - 160/9)

您可以尝试:

convertion = int((5 * convertion) / 9 - 160 / 9)
,
temperature = input("enter a temperature as you wish: ")

conversion = int(temperature[:-1])

if temperature[-1] == "C":

    conversion = int((9 * conversion) / 5 + 32)

    temperature = str(conversion) + "F"

elif temperature[-1] == "F":

    conversion = int((5 * conversion) / 9 - 160 / 9)

    temperature = str(conversion) + "C"

print(temperature)

您可以尝试使用上面的代码吗?虽然没有太大变化!

本文链接:https://www.f2er.com/2650872.html

大家都在问