我正在尝试将此米转换为千米,但我不知道如何让输入实现它是一个整数
m = input("Enter the distance (meters) you want to convert to kilometers ")
km = 1000
print (m/km,"km")
答案 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")
请注意使用m
将str
从int
转换为int()