Question:
Define a function that can generate and print a list where the values are squares of numbers between 1 and 20 (both included).
Hints:
- Use the ** operator to get the power of a number.
- Use range() for loops.
- Use list.append() to add values into a list.
Solution:
def printList():
li=list()
for i in range(1,21):
li.append(i**2)
print li
printList()
Code language: Python (python)