我究竟做错了什么? (皈依)

时间:2015-09-06 12:26:39

标签: python

我正在尝试将此米转换为千米,但我不知道如何让输入实现它是一个整数

m = input("Enter the distance (meters) you want to convert to kilometers  ")
km =  1000
print (m/km,"km")

2 个答案:

答案 0 :(得分:2)

如果你使用Python 3,你可以这样做:

要获取int,请执行m = int(input("Enter int"))

因此,在您的代码中,只需将input()更改为int(input())

m = int(input("Enter the distance (meters) you want to convert to kilometers  "))
km =  1000
print (m/km,"km")

答案 1 :(得分:1)

m = int(input("Enter the distance you want to convert (meters) "))
km =  1000
print (m/km,"km")

请注意使用mstrint转换为int()