给我一个频率范围start
,end
和一个整数n:1<=n<=5
。任务是按某种格式打印所有5个线性间隔的中点(供下游的其他工具进行进一步处理。此部分不在此处)
如果n
小于5,则最后的频率变量应在打印中默认为0
。我在下面给出了一个有效的代码。我想获得更多的“ pythonic”重构。我特别不喜欢的片段部分:
代码段:-
import sys
import numpy as np
max = 5
n=int(sys.argv[1])
if n>max:
print("No of frequency larger than "+ str(max) + " ..resetting")
n=max
if n<1:
print("No of frequency less than 1 resetting to 1")
n=1
fr1=0
fr2=0
fr3=0
fr4=0
fr5=0
start = 5060000
end = 6165000
range = end-start
inc = range/(n+1)
ret_list = np.arange(start+inc,end,inc).tolist()[:n]
ret_list = ret_list + [0]*(max-n)
fr1,fr2,fr3,fr4,fr5 = ret_list
print(".fr1.",fr1, sep = '')
print(".fr2.",fr2, sep = '')
print(".fr3.",fr3, sep = '')
print(".fr4.",fr4, sep = '')
print(".fr5.",fr5, sep = '')