在Python中定义范围命令的条件

时间:2018-11-02 13:29:40

标签: python projection map-projections

我仍然是Python编码的初学者,在完成此任务后,我必须定义子午线和纬线的制图Lambert投影的计算。该代码有效,但不如我所愿。

我的目标是在x的值大于100时取消计算,但是对于range命令,我无法使其生效。简单地说,如果结果是x> 100,则打印“-”而不是结果似乎无效。

Range给出多个结果(由用户定义多少个结果),并且当这样写时,它似乎不能与if条件一起使用:

import math
import sys    
projection = input("Input the name of projection (L, A, M, B):")

if projection == "L":
print("Lambert projection")
v = int(input("Define interval in which the meridians will be calculated"))
if v <= 0:
    sys.exit("interval must be higher than 0")
s = int(input("Define scale 1:(input)"))
if s <= 0:
    sys.exit("scale must have higher value than 0")
R = 6371.11
n = int(input("How many meridians to project? (from center)"))
if n <=0:
    sys.exit("Number must be higher than 0")
for v in range(n):
    #It will repeat the equation the many times its defined in n input
    x = R*(v*n)
    if x/s<=100:
        print("meridian will be", x/s, "cm from center")
    else:
        print("meridian will be - cm from center")

还有另一种选择,可以列出范围命令的结果列表,但是我不确定如何为范围命令进行列表。

任何帮助将不胜感激。

0 个答案:

没有答案