Skip to content

Commit bdf3551

Browse files
committed
day 18 code is updated
1 parent b816bcc commit bdf3551

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

Status/Day_18.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ print random.choice([i for i in range(11) if i%2==0])
2121
----------------
2222
**My Solution: Python 3**
2323
```python
24-
#to be written
25-
24+
import random
25+
resp = [i for i in range(2,11,2)]
26+
print(random.choice(resp))
2627
```
2728
---------------------
2829

2930

30-
3131
# Question 71
3232

3333
### **Question**
3434

35-
>***Please write a program to output a random number, which is divisible by 5 and 7, between 0 and 10 inclusive using random module and list comprehension.***
35+
>***Please write a program to output a random number, which is divisible by 5 and 7, between 10 and 150 inclusive using random module and list comprehension.***
3636
3737
----------------------
3838
### Hints
@@ -43,13 +43,14 @@ print random.choice([i for i in range(11) if i%2==0])
4343
**Main author's Solution: Python 2**
4444
```python
4545
import random
46-
print random.choice([i for i in range(201) if i%5==0 and i%7==0])
46+
print random.choice([i for i in range(10,151) if i%5==0 and i%7==0])
4747
```
4848
----------------
4949
**My Solution: Python 3**
5050
```python
51-
#to be written
52-
51+
import random
52+
resp = [i for i in range(10,151) if i % 35 == 0 ]
53+
print(random.choice(resp))
5354
```
5455
---------------------
5556

@@ -69,14 +70,14 @@ print random.choice([i for i in range(201) if i%5==0 and i%7==0])
6970
```python
7071

7172
import random
72-
print random.sample(range(100), 5)
73-
73+
print random.sample(range(100,201), 5)
7474
```
7575
----------------
7676
**My Solution: Python 3**
7777
```python
78-
#to be written
79-
78+
import random
79+
resp = random.sample(range(100,201),5)
80+
print(resp)
8081
```
8182
---------------------
8283

@@ -103,8 +104,9 @@ print random.sample([i for i in range(100,201) if i%2==0], 5)
103104
----------------
104105
**My Solution: Python 3**
105106
```python
106-
#to be written
107-
107+
import random
108+
resp = random.sample(range(100,201,2),5)
109+
print(resp)
108110
```
109111
---------------------
110112

@@ -132,8 +134,10 @@ print random.sample([i for i in range(1,1001) if i%5==0 and i%7==0], 5)
132134
----------------
133135
**My Solution: Python 3**
134136
```python
135-
#to be written
136-
137+
import random
138+
lst = [i for i in range(1,1001) if i%35 == 0]
139+
resp = random.sample(lst,5)
140+
print(resp)
137141
```
138142
---------------------
139143

0 commit comments

Comments
 (0)