Help with python range question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Help with python range question

Need help with this python question https://code.sololearn.com/cv8ZfMYNtNmc/?ref=app

22nd Jul 2018, 11:28 PM
Chris Sheffield
Chris Sheffield - avatar
7 Answers
+ 1
for power in range(7): calculation=2**power print('2 to the {} is {}'.format(power, calculation))
22nd Jul 2018, 11:55 PM
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ - avatar
+ 2
that?)
22nd Jul 2018, 11:55 PM
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ - avatar
+ 1
I get that, need to tie it somehow to the variables of power and calculation as per the last line
22nd Jul 2018, 11:44 PM
Chris Sheffield
Chris Sheffield - avatar
+ 1
This may help: ---------- for power in range(7): calculation = 2 ** power print('2 to the {} is {}'.format(power, calculation)) ---------- This outputs: >> 2 to the 0 is 1 >> 2 to the 1 is 2 >> 2 to the 2 is 4 >> 2 to the 3 is 8 >> 2 to the 4 is 16 >> 2 to the 5 is 32 >> 2 to the 6 is 64 ---------- Pretty sure that follows the instructions. Could be completed with list comprehension, but the question did specify a for-loop.
23rd Jul 2018, 1:54 AM
Paul Griz
Paul Griz - avatar
0
if i'm understood correctly: for i in range(7): print(i**2)
22nd Jul 2018, 11:42 PM
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ - avatar
0
ouch!)
22nd Jul 2018, 11:55 PM
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ
ะะฝะดั€ะตะน ะšะพะฑะพะทะตะฒ - avatar
0
a = [x**2 for x in range(7)] print(a)
23rd Jul 2018, 12:00 AM
Harry
Harry - avatar