Give me idea how can i solve this simple programme. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Give me idea how can i solve this simple programme.

Problem and my code is given below https://www.sololearn.com/coach/1101?ref=app

17th Jul 2021, 12:10 PM
Md Abu Taher
Md Abu Taher - avatar
5 Answers
+ 1
Md Abu Taher List comprehension is a concept in Python. You have to read about how to use it. It replace an ordinary for loop. (You can of course solve your problem with an ordinary for loop, but this wasn’t really the task, was it? Nope, the task was to learn how to use list comprehensions.)
17th Jul 2021, 1:27 PM
Per Bratthammar
Per Bratthammar - avatar
+ 3
Well, that's a pro content non-pros can't access that. You have to give some description of the task and share your attempt so someone from the community can help //are you on pro? your profile doesn't confirm that
17th Jul 2021, 12:19 PM
Daljeet Singh
Daljeet Singh - avatar
+ 1
Try use list comprehension. The formula is in the task: number_of_insects * 2 ** month The number of insectes comes from input(). The number of month you have to specify as an exceeding list, or a range(), like [0, 1, 2, …, 11]. Then put it an comprension list: [f(i) for i in <container>]. Thats all, and he output will be a list with 12 element, where the inputwd value will double for every month.
17th Jul 2021, 12:34 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Daljeet Singh My code n = int(input()) for i in range(0,12): print(n*(2**i))
17th Jul 2021, 12:41 PM
Md Abu Taher
Md Abu Taher - avatar
+ 1
Per Bratthammar Yes i understand it but i can not put the output in list. my code: n = int(input()) for i in range(0,12): print(n*(2**i))
17th Jul 2021, 12:42 PM
Md Abu Taher
Md Abu Taher - avatar