Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with list
#3
(Jan-30-2019, 04:39 PM)perfringo Wrote: You created empty list. Therefore index is out of range:

>>> luck = list()
>>> len(luck)
0
>>> luck[0]
/..../
IndexError: list index out of range
You should use append.

You also ask two times for input for both a and b.

One way of writing this code:

>>> a = int(input("Give number a: "))
>>> b = int(input("Give number b: "))
>>> luck = list()
for i in range(b):
...    luck.append(a**b)
Of course, if task is [a^0,a^1,a^2,...,a^b] then one should append (a**i)

thanks but it's not working either
what i want is to print the follow :
example a=2 b=4
should print [2^0,2^1,2^2,2^3,2^4] which is [1,2,4,8,16]
Reply


Messages In This Thread
help with list - by sonedap - Jan-30-2019, 04:18 PM
RE: help with list - by perfringo - Jan-30-2019, 04:39 PM
RE: help with list - by sonedap - Jan-30-2019, 04:47 PM
RE: help with list - by perfringo - Jan-30-2019, 04:56 PM
RE: help with list - by sonedap - Jan-30-2019, 05:28 PM
RE: help with list - by ichabod801 - Jan-30-2019, 05:37 PM
RE: help with list - by sonedap - Jan-30-2019, 05:50 PM
RE: help with list - by ichabod801 - Jan-30-2019, 07:18 PM
RE: help with list - by nilamo - Jan-30-2019, 09:00 PM
RE: help with list - by sonedap - Jan-31-2019, 08:48 AM
RE: help with list - by sonedap - Jan-31-2019, 09:51 AM
RE: help with list - by perfringo - Jan-31-2019, 10:19 AM
RE: help with list - by sonedap - Jan-31-2019, 10:37 AM
RE: help with list - by perfringo - Jan-31-2019, 11:04 AM
RE: help with list - by sonedap - Jan-31-2019, 11:20 AM
RE: help with list - by perfringo - Jan-31-2019, 11:55 AM
RE: help with list - by sonedap - Jan-31-2019, 02:30 PM
RE: help with list - by perfringo - Jan-31-2019, 02:33 PM
RE: help with list - by sonedap - Jan-31-2019, 04:44 PM
RE: help with list - by perfringo - Jan-31-2019, 04:57 PM
RE: help with list - by sonedap - Feb-01-2019, 07:56 AM
RE: help with list - by ichabod801 - Feb-01-2019, 03:52 PM
RE: help with list - by sonedap - Feb-01-2019, 04:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020