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)

25th Jun 2021, 10:51 PM
Sid
Sid - avatar
9 Respostas
+ 3
# or maybe: p = [n*2**i for i in range(12)]
25th Jun 2021, 10:57 PM
visph
visph - avatar
+ 5
#try this n = int(input()) l=[n*2**i for i in range(12)] print(l);
19th Jul 2022, 2:50 PM
shiwana
shiwana - avatar
0
p = [n*2**i for i in range(1,13)]
25th Jun 2021, 10:55 PM
visph
visph - avatar
0
n = int(input()) for i in range(1,13): p = [n*2**i for i in range(0,12)] print(p)
11th Sep 2021, 8:10 PM
guenaizi abdelkader
guenaizi abdelkader - avatar
0
print(list(n*2**i for i in range(12)))
1st Oct 2021, 7:57 AM
jiaqi chen
jiaqi chen - avatar
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.
22nd Jun 2022, 8:12 AM
Ashim Ranjit
0
22nd Jun 2022, 8:26 AM
Ashim Ranjit
0
n = int(input()) print([n*2**i for i in range(12)])
2nd Dec 2022, 10:12 AM
Pareshkumar Chaudhari
0
n = int(input()) owady = [n * 2 ** i for i in range(12)] print(owady)
25th Apr 2023, 3:07 PM
Kapitan Dominik Łempicki
Kapitan Dominik Łempicki - avatar