File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,33 @@ printDict()
6464
6565# Question 33
6666### level 1
67+
68+ ** Question:**
69+
70+ *** Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included).***
71+
72+ ----------------------
73+ ### Hints:
74+ #### Use ** operator to get power of a number.Use range() for loops.Use list.append() to add values into a list.
75+
76+ -------------------
77+ ** Main Author's Solution: Python 2**
78+ ```
79+ def printList():
80+ li=list()
81+ for i in range(1,21):
82+ li.append(i**2)
83+ print li
84+
85+ printList()
86+ ```
87+ ----------------
88+ ** My Solution: Python 3**
89+ ```
90+ def printDict():
91+ lst = [i ** 2 for i in range(1, 21)]
92+ print(lst)
93+
94+ printDict()
95+ ```
96+ -------------------
You can’t perform that action at this time.
0 commit comments