-5
我正在尝试使用用户输入来结束程序。我希望他们只需点击当他们需要退出时输入。我究竟做错了什么?结束用户输入的Python程序
# 1)Pace.py
# Converts miles per hour to minutes per mile.
print ("Hello! This program will convert the miles per hour you got on your treadmill to >minutes per mile.") # Greeting
def main() : # Defines the function main
while True : # The loop can repeat infinitely for multiple calculations.
mph = eval (input ("Please enter your speed in miles per hour. ")) # Asks for >user input and assigns it to mph.
mpm = 1/(mph/60) # The user input is divided by 60, and that is divided by 1. >This is assigned to mpm.
print ("Your speed was", mpm, "minutes per mile!") # Prints out the miles per >minute.
if mph == input ("") : # If the user entered nothing...
break # ...The program stops
main() # Runs main.
请修正你的代码 - 这不能是你的原程序。无论如何,你可能希望'如果mph ==“”'没有输入。我强烈建议不要以这种方式使用“eval”,这是非常危险的。 – mdurant 2014-09-05 19:14:54
你为什么使用eval? – 2014-09-05 19:14:55
你不应该在输入中使用'eval'。强制转换为int [ – 2014-09-05 19:15:15