0
Python Data Structures - Insect Control
So I've never been any good at list comprehensions. Could someone give a working answer to this problem? Task: The number of insects in a lab doubles in size every month. Take the initial number of insects as input and output a list, showing the number of insects for each of the next 12 months, starting with 0, which is the initial value. So, the resulting list should contain 12 items, each showing the number of insects at the beginning of that month. Create a list comprehension to generate the required list. My solution: n = int(input()) p = [i*2**n for i in range(1,12)] print(p)
9 Respuestas
+ 3
# or maybe:
p = [n*2**i for i in range(12)]
+ 5
#try this
n = int(input())
l=[n*2**i for i in range(12)]
print(l);
0
p = [n*2**i for i in range(1,13)]
0
n = int(input())
for i in range(1,13):
p = [n*2**i for i in range(0,12)]
print(p)
0
print(list(n*2**i for i in range(12)))
0
n = int(input())
list= [n]
for i in range(11):
new_value = n*2
list.append((new_value))
n = new_value
print(list)
#there's many way. you just need to find your way.
0
0
n = int(input())
print([n*2**i for i in range(12)])
0
n = int(input())
owady = [n * 2 ** i for i in range(12)]
print(owady)