r/pythonhelp • u/Neat_Chip4684 • Aug 31 '21
HOMEWORK Help with Python exponential function
So, I started my coding adventure yesterday and started from "4 hours full course for beginners of python". I had problems understanding how below code works, it's exponential function and I can't really understand It.After defining a function, we make container called "result" where we store below list of numbers and I can't understand how its gonna make 2^3=8? How can list of numbers be multiplied by 2? Someone can help?


3
Upvotes
2
u/sentles Nov 15 '22
range(5)is a range object containing[0, 1, 2, 3, 4], a total of 5 integers. If you were to runraise_to_power(2, 5), the result would be 32 because on each iteration,resultis multiplied by 2. Since it starts at 1 and we have a total of 5 iterations (fromi=0up to and includingi=4), the final value saved inresultis going to be1*2*2*2*2*2, or 32.