Printing in list form

numbers = [7, 9, 12, 54, 99]
for number in numbers:
print(number ** 2)

Above code print result in up down order but I want to print result in list form? Is it possible?

yes, its possible. I could tell you how to achieve this, but then we waste a valuable learning opportunity. How do you think this could be achieved? Not in code, just try to describe it.

numbers = [7, 9, 12, 54, 99]
for number in numbers:
print(numbers[number] **2)
I tried this but it show IndexError: list index out of range

numbers = [7, 9, 12, 54, 99]
def numb(number):
for numbers in number:
return numbers ** 2
print (numb(numbers))
tried this as well ? :frowning:

Why did you try those things? Why did you think they would work?

Variable goes through each numbers inside list. So, I think printing (numbers[number] ** 2) will print numbers list with index variable squared.

why do you want the index squared? This won’t work because number might have an higher value then that there are indexes, so you might get an index error

if you want indexes, use range() with length of list as argument

for number in numbers:

numbers = [7, 9, 12, 54, 99]
word= []
def lists_view(number):
for numb in number:
word.append(numb ** 2)
return word
Finally I did it :slight_smile: Sir.