Bacteria problem 5.2
Hi. Total beginner here. The bacteria problem formula is; 500* 2 ** N . N goes sequentially up to 30 So I coded: (500 * 2 ** N), N = range (30) I looked up the N= range () on Google but was not correct. Would appreciate guidance. Thank you
4/13/2021 11:35:03 PMPeter
11 AnswersNew Answer
I think this is what you need for N in range(30): print(500 *2 **N) create a range, then apply your formula where N is the power being generated by the range. The print function will show the result of each iteration
Loser I know it is a small joke I will try to help
Codemurai while humour lightens and brightens the place - it's less helpful in helping with the solution. Nice Joke, btw. 🙂
Thank you Rik and Loser....Im at preset pretty hopeless ...so far... in the Python Peter
@Peter You can try "Programming with Python for Absolute Beginners - 'Mike Dawson' ". Really, Good one. It's the same book I refer to my students. OR you can try programiz.com, really a great reference. This place is just for practice, revision and doubt-solving.
Thank you Loser I will order the book
This will help you and it's the right answer!! N=24 print(500*2**N) SIMPLE..!! No need to use for loop for this..
It is simple to done . First step - what has given to us. Second - write bacteria =500, n=24. Third - use (500*2**n). That's it and run the code you get the result.
N = 30 for i in range(N): i = i + 1 print(500 * 2 ** i) range function works with 'for' loops, not alone.. you would require to have a variable, in this case 'i', that will intake the value N gives out from '0' till 'N'. As the value for 'i' starts from 0, we have to have statement/expression that will change it's value from 0 to 1, (hence, the statement - i = i + 1) inorder to get the desired output.
Hmmmm...... Lot of bacteria Use a Dettol Print("Dettol")
For input, just enter the number of hours you would like to calculate. Hours = (input()) print (500*2**int(Hours))