Skip to content

Commit 7c70be8

Browse files
authored
Update Day_10.md
1 parent 78c3146 commit 7c70be8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Status/Day_10.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,42 @@ def printList():
9494
printList()
9595
```
9696
-------------------
97+
98+
# Question 34
99+
### level 1
100+
101+
**Question:**
102+
103+
***Define a function which can generate a list where the values are square of numbers between 1 and 20 (both included). Then the function needs to print the first 5 elements in the list.***
104+
105+
----------------------
106+
### Hints:
107+
#### Use ** operator to get power of a number.Use range() for loops.Use list.append() to add values into a list.Use [n1:n2] to slice a list
108+
109+
-------------------
110+
**Main Author's Solution: Python 2**
111+
```
112+
def printList():
113+
li=list()
114+
for i in range(1,21):
115+
li.append(i**2)
116+
print li[:5]
117+
118+
printList()
119+
```
120+
----------------
121+
122+
**My Solution: Python 3**
123+
```
124+
def printList():
125+
lst = [i ** 2 for i in range(1, 21)]
126+
127+
for i in range(5):
128+
print(lst[i])
129+
130+
printList()
131+
```
132+
-------------
133+
# Question 35
134+
### level 1
135+

0 commit comments

Comments
 (0)