Python List Comprehension | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python List Comprehension

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. n= int(input)) d = [n**I for I in range(n - 1, 13)] print(d) I got the test case 1 but the test case 2 output empty list

11th Jan 2022, 9:15 PM
Adewale Obalanlege
Adewale Obalanlege - avatar
4 Answers
+ 3
I have solved it. n = int(input()) double_n = [n*2**i for i in range(12)] print(double_n)
11th Jan 2022, 9:35 PM
Adewale Obalanlege
Adewale Obalanlege - avatar
+ 3
Thank you 😊
11th Jan 2022, 9:38 PM
Adewale Obalanlege
Adewale Obalanlege - avatar
11th Jan 2022, 9:28 PM
Adewale Obalanlege
Adewale Obalanlege - avatar
0
n = int(input()) double_n = [2*n**i for i in range(12)] print(double_n)
11th Jan 2022, 9:30 PM
Adewale Obalanlege
Adewale Obalanlege - avatar