Python 公里与英里的换算

Python 公里与英里的换算,python,function,variables,input,output,Python,Function,Variables,Input,Output,这是一个将公里转换为英里的程序,但是,每次我运行它时,都没有一行要求输入,就像它应该的那样,它总是空白的 代码如下: KILOMETERS_TO_MILES =float(0.6214) def main(): Distance = input("please input the distance in kilometers to wish to convert:")) showMiles(Distance) def showmiles(Distance): mile

这是一个将公里转换为英里的程序,但是,每次我运行它时,都没有一行要求输入,就像它应该的那样,它总是空白的

代码如下:

KILOMETERS_TO_MILES =float(0.6214)

def main():
    Distance = input("please input the distance in kilometers to wish to convert:"))
    showMiles(Distance)

def showmiles(Distance):
    miles = Distance * KILOMETERS_TO_MILES
    print=("Conversion of ", Distance,"kilometers to miles: ", miles, "miles")

main()
这应该起作用:

KILOMETERS_TO_MILES = 0.621371

def show_miles(Distance):
    miles = Distance * KILOMETERS_TO_MILES
    print('Conversion of {} kilometers to miles: {} miles'.format(Distance, miles))

def main():
    Distance = float(input("please input the distance in kilometers you wish to convert: "))
    show_miles(Distance)

main()
您的原始代码有几个问题:

KILOMETERS_TO_MILES =float(0.6214)

def main():
    # You have an extra closing ')' on the next line
    Distance = input("please input the distance in kilometers to wish to convert: "))
    showMiles(Distance)  # this showMiles has an upper case 'M'

def showmiles(Distance):  # this showmiles has a lower case 'm'
    miles = Distance * KILOMETERS_TO_MILES
    # You have an = sign on the next line that shouldn't be there
    print=("Conversion of ", Distance,"kilometers to miles: ", miles, "miles")

main()

看起来部分问题来自你的第三行。我注意到你有两个右括号),但你只有一个右括号。
“..

请修复问题中的代码缩进。如前所述,这不可能是有效的Python代码。如果您使用的是所示的代码,您应该会遇到语法错误。语法错误,几周后没有更新……这实际上应该关闭……并丢弃。正如其他答案(以及其他问题)在7个月前所述。