Skip to content

Commit 1e2b562

Browse files
authored
Add files via upload
1 parent 66ddf95 commit 1e2b562

File tree

2 files changed

+304
-0
lines changed

2 files changed

+304
-0
lines changed

Status/Day_17.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
2+
# Question 65
3+
4+
### **Question**
5+
6+
>***Please write assert statements to verify that every number in the list [2,4,6,8] is even.***
7+
8+
9+
----------------------
10+
### Hints
11+
> ***Use "assert expression" to make assertion.***
12+
13+
----------------------
14+
15+
**Main author's Solution: Python 2**
16+
```python
17+
li = [2,4,6,8]
18+
for i in li:
19+
assert i%2==0
20+
```
21+
----------------
22+
**My Solution: Python 3**
23+
```python
24+
#to be written
25+
26+
```
27+
---------------------
28+
29+
30+
31+
# Question 66
32+
33+
### **Question**
34+
35+
>***Please write a program which accepts basic mathematic expression from console and print the evaluation result.***
36+
37+
>***Example:
38+
If the following n is given as input to the program:***
39+
```
40+
35 + 3
41+
```
42+
>***Then, the output of the program should be:***
43+
```
44+
38
45+
```
46+
47+
----------------------
48+
### Hints
49+
> ***Use eval() to evaluate an expression.***
50+
51+
----------------------
52+
53+
**Main author's Solution: Python 2**
54+
```python
55+
expression = raw_input()
56+
print eval(expression)
57+
```
58+
----------------
59+
**My Solution: Python 3**
60+
```python
61+
#to be written
62+
63+
```
64+
---------------------
65+
66+
# Question 67
67+
68+
### **Question**
69+
70+
>***Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list.***
71+
72+
----------------------
73+
### Hints
74+
>***Use if/elif to deal with conditions.***
75+
76+
----------------------
77+
78+
**Main author's Solution: Python 2**
79+
```python
80+
import math
81+
def bin_search(li, element):
82+
bottom = 0
83+
top = len(li)-1
84+
index = -1
85+
while top>=bottom and index==-1:
86+
mid = int(math.floor((top+bottom)/2.0))
87+
if li[mid]==element:
88+
index = mid
89+
elif li[mid]>element:
90+
top = mid-1
91+
else:
92+
bottom = mid+1
93+
94+
return index
95+
96+
li=[2,5,7,9,11,17,222]
97+
print bin_search(li,11)
98+
print bin_search(li,12)
99+
100+
```
101+
----------------
102+
**My Solution: Python 3**
103+
```python
104+
#to be written
105+
106+
```
107+
---------------------
108+
109+
110+
# Question 68
111+
112+
### **Question**
113+
114+
>***Please generate a random float where the value is between 10 and 100 using Python math module.***
115+
116+
----------------------
117+
### Hints
118+
> ***Use random.random() to generate a random float in [0,1].***
119+
120+
----------------------
121+
122+
**Main author's Solution: Python 2**
123+
```python
124+
import random
125+
print random.random()*100
126+
127+
```
128+
----------------
129+
**My Solution: Python 3**
130+
```python
131+
#to be written
132+
133+
```
134+
---------------------
135+
136+
137+
138+
# Question 69
139+
140+
### **Question**
141+
142+
>***Please generate a random float where the value is between 5 and 95 using Python math module.***
143+
144+
145+
----------------------
146+
### Hints
147+
> ***Use random.random() to generate a random float in [0,1].***
148+
149+
----------------------
150+
151+
**Main author's Solution: Python 2**
152+
```python
153+
import random
154+
print random.random()*100-5
155+
```
156+
----------------
157+
**My Solution: Python 3**
158+
```python
159+
#to be written
160+
161+
```
162+
---------------------
163+
164+

Status/Day_18.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
# Question 70
3+
4+
### **Question**
5+
6+
>***Please write a program to output a random even number between 0 and 10 inclusive using random module and list comprehension.***
7+
8+
9+
----------------------
10+
### Hints
11+
> ***Use random.choice() to a random element from a list.***
12+
13+
----------------------
14+
15+
**Main author's Solution: Python 2**
16+
```python
17+
li = [2,4,6,8]
18+
import random
19+
print random.choice([i for i in range(11) if i%2==0])
20+
```
21+
----------------
22+
**My Solution: Python 3**
23+
```python
24+
#to be written
25+
26+
```
27+
---------------------
28+
29+
30+
31+
# Question 71
32+
33+
### **Question**
34+
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.***
36+
37+
----------------------
38+
### Hints
39+
> ***Use random.choice() to a random element from a list.***
40+
41+
----------------------
42+
43+
**Main author's Solution: Python 2**
44+
```python
45+
import random
46+
print random.choice([i for i in range(201) if i%5==0 and i%7==0])
47+
```
48+
----------------
49+
**My Solution: Python 3**
50+
```python
51+
#to be written
52+
53+
```
54+
---------------------
55+
56+
# Question 72
57+
58+
### **Question**
59+
60+
>***Please write a program to generate a list with 5 random numbers between 100 and 200 inclusive.***
61+
62+
----------------------
63+
### Hints
64+
>***Use random.sample() to generate a list of random values.***
65+
66+
----------------------
67+
68+
**Main author's Solution: Python 2**
69+
```python
70+
71+
import random
72+
print random.sample(range(100), 5)
73+
74+
```
75+
----------------
76+
**My Solution: Python 3**
77+
```python
78+
#to be written
79+
80+
```
81+
---------------------
82+
83+
84+
# Question 73
85+
86+
### **Question**
87+
88+
>***Please write a program to randomly generate a list with 5 even numbers between 100 and 200 inclusive.***
89+
90+
----------------------
91+
### Hints
92+
> ***Use random.sample() to generate a list of random values.***
93+
94+
----------------------
95+
96+
**Main author's Solution: Python 2**
97+
```python
98+
99+
import random
100+
print random.sample([i for i in range(100,201) if i%2==0], 5)
101+
102+
```
103+
----------------
104+
**My Solution: Python 3**
105+
```python
106+
#to be written
107+
108+
```
109+
---------------------
110+
111+
112+
113+
# Question 74
114+
115+
### **Question**
116+
117+
>***Please write a program to randomly generate a list with 5 numbers, which are divisible by 5 and 7 , between 1 and 1000 inclusive.***
118+
119+
120+
----------------------
121+
### Hints
122+
> ***Use random.sample() to generate a list of random values.***
123+
124+
----------------------
125+
126+
**Main author's Solution: Python 2**
127+
```python
128+
129+
import random
130+
print random.sample([i for i in range(1,1001) if i%5==0 and i%7==0], 5)
131+
```
132+
----------------
133+
**My Solution: Python 3**
134+
```python
135+
#to be written
136+
137+
```
138+
---------------------
139+
140+

0 commit comments

Comments
 (0)