+ 4
Help with python range question
Need help with this python question https://code.sololearn.com/cv8ZfMYNtNmc/?ref=app
7 Antworten
+ 1
for power in range(7):
calculation=2**power
print('2 to the {} is {}'.format(power, calculation))
+ 2
that?)
+ 1
I get that, need to tie it somehow to the variables of power and calculation as per the last line
+ 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.
0
if i'm understood correctly:
for i in range(7):
print(i**2)
0
ouch!)
0
a = [x**2 for x in range(7)]
print(a)