Python 我怎样才能弄干一段代码,它接收多个输入,对每个输入执行相同的函数,并同时给出所有输出?
我正在编写一个代码,可以同时计算和显示4条跑道的侧风分量。在输入(选定跑道)和输出(侧风分量)之间,我有4个代码块,每个跑道使用相同的计算。为了简单起见,我写了一个replex:Python 我怎样才能弄干一段代码,它接收多个输入,对每个输入执行相同的函数,并同时给出所有输出?,python,python-3.x,dry,Python,Python 3.x,Dry,我正在编写一个代码,可以同时计算和显示4条跑道的侧风分量。在输入(选定跑道)和输出(侧风分量)之间,我有4个代码块,每个跑道使用相同的计算。为了简单起见,我写了一个replex: first_runway = int(input("Enter the 1st runway")) second_runway = int(input("Enter the 2nd runway")) third_runway = int(input("Enter the 3rd runway")) fourth_ru
first_runway = int(input("Enter the 1st runway"))
second_runway = int(input("Enter the 2nd runway"))
third_runway = int(input("Enter the 3rd runway"))
fourth_runway = int(input("Enter the 4th runway"))
crosswind1 = first_runway * 2
crosswind2 = second_runway * 2
crosswind3 = third_runway * 2
crosswind4 = fourth_runway * 2
print(crosswind1, crosswind2, crosswind3, crosswind4)
有没有办法只使用一次“*2”?这是简单的Python。您可以这样做:
value = []
for i in range(1, 5):
runway = int(input("Enter the {}st runway".format(i)))
crosswind = runway * 2
value.append(crosswind)
print(value)
尝试使用for循环循环4次。不应该太难解渴跑道:DYup。你知道的;)