# 我不明白为什么我的 python 代码没有返回以英里为单位的答案

2023-08-22 18:01:53

## 2 回答

TA贡献1865条经验 获得超7个赞

1. 在使用它进行计算之前，您的输入语句必须转换为 int`nauticalmile = onekilo*Kilometers`

2. 你的除法语句有一个逗号。Python 会将逗号视为另一个变量。`onekilo = degreesPerMin/10,000`所以删除这个语句中的逗号

3. 您的打印报表需要更新。当您只想显示信息时，请勿在打印语句中使用输入语句。另外，用适当的引号分隔字符串和变量。`print =input("Kilometers,is,nauticalmile,Nautical miles")`需要编辑为`print (Kilometers,"is",nauticalmile,"Nautical miles")`

• 一公里代表北极与赤道之间距离的1/10,000。

• 北极和赤道之间有 90 度，每个包含 60 分弧。

• 一海里是一弧分。

Kilometers=input("Enter the amount of kilometers:")

degreesPerMin = 90*60

onekilo = degreesPerMin/10,000

nauticalmile = onekilo*Kilometers

print =input("Kilometers,is,nauticalmile,Nautical miles")Kilometers=int(input("Enter the amount of kilometers:"))

degreesPerMin = 90*60

onekilo = degreesPerMin/10000

nauticalmile = onekilo*Kilometers

print (Kilometers,"is",nauticalmile,"Nautical miles")

Enter the amount of kilometers:200

200 is 108.0 Nautical miles

TA贡献1830条经验 获得超3个赞

Kilometers=int(input("Enter the amount of kilometers:"))#datatype is declared(int)

degreesPerMin = 90*60

onekilo = degreesPerMin/10000

nauticalmile = onekilo*Kilometers

print("Kilometers =",Kilometers)#the variable name shouldn't be inside brackets(Kilometers)

print("degreesPerMin =",degreesPerMin)

print("onekilo =",onekilo)

print("nauticalmile =",nauticalmile)

• 2 回答
• 0 关注
• 107 浏览

0/150