Skip to content

Commit c881274

Browse files
authored
Add files via upload
1 parent 1e2b562 commit c881274

File tree

4 files changed

+641
-0
lines changed

4 files changed

+641
-0
lines changed

Status/Day_19.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
2+
# Question 75
3+
4+
### **Question**
5+
6+
>***Please write a program to randomly print a integer number between 7 and 15 inclusive.***
7+
8+
9+
----------------------
10+
### Hints
11+
> ***Use random.randrange() to a random integer in a given range.***
12+
13+
----------------------
14+
15+
**Main author's Solution: Python 2**
16+
```python
17+
import random
18+
print random.randrange(7,16)
19+
```
20+
----------------
21+
**My Solution: Python 3**
22+
```python
23+
#to be written
24+
25+
```
26+
---------------------
27+
28+
29+
30+
# Question 76
31+
32+
### **Question**
33+
34+
>***Please write a program to compress and decompress the string "hello world!hello world!hello world!hello world!".***
35+
36+
----------------------
37+
### Hints
38+
> ***Use zlib.compress() and zlib.decompress() to compress and decompress a string.***
39+
40+
----------------------
41+
42+
**Main author's Solution: Python 2**
43+
```python
44+
import zlib
45+
s = 'hello world!hello world!hello world!hello world!'
46+
t = zlib.compress(s)
47+
print t
48+
print zlib.decompress(t)
49+
```
50+
----------------
51+
**My Solution: Python 3**
52+
```python
53+
#to be written
54+
55+
```
56+
---------------------
57+
58+
# Question 77
59+
60+
### **Question**
61+
62+
>***Please write a program to print the running time of execution of "1+1" for 100 times.***
63+
64+
----------------------
65+
### Hints
66+
>***Use timeit() function to measure the running time.***
67+
68+
----------------------
69+
70+
**Main author's Solution: Python 2**
71+
```python
72+
73+
from timeit import Timer
74+
t = Timer("for i in range(100):1+1")
75+
print t.timeit()
76+
```
77+
----------------
78+
**My Solution: Python 3**
79+
```python
80+
#to be written
81+
82+
```
83+
---------------------
84+
85+
86+
# Question 78
87+
88+
### **Question**
89+
90+
>***Please write a program to shuffle and print the list [3,6,7,8].***
91+
92+
----------------------
93+
### Hints
94+
> ***Use shuffle() function to shuffle a list.***
95+
96+
----------------------
97+
98+
**Main author's Solution: Python 2**
99+
```python
100+
101+
from random import shuffle
102+
li = [3,6,7,8]
103+
shuffle(li)
104+
print li
105+
106+
```
107+
----------------
108+
**My Solution: Python 3**
109+
```python
110+
#to be written
111+
112+
```
113+
---------------------
114+
115+
116+
117+
# Question 79
118+
119+
### **Question**
120+
121+
>***Please write a program to generate all sentences where subject is in ["I", "You"] and verb is in ["Play", "Love"] and the object is in ["Hockey","Football"].***
122+
123+
124+
----------------------
125+
### Hints
126+
> ***Use list[index] notation to get a element from a list.***
127+
128+
----------------------
129+
130+
**Main author's Solution: Python 2**
131+
```python
132+
133+
subjects=["I", "You"]
134+
verbs=["Play", "Love"]
135+
objects=["Hockey","Football"]
136+
for i in range(len(subjects)):
137+
for j in range(len(verbs)):
138+
for k in range(len(objects)):
139+
sentence = "%s %s %s." % (subjects[i], verbs[j], objects[k])
140+
print sentence
141+
```
142+
----------------
143+
**My Solution: Python 3**
144+
```python
145+
#to be written
146+
147+
```
148+
---------------------
149+
150+

Status/Day_20.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
2+
# Question 80
3+
4+
### **Question**
5+
6+
>***Please write a program to print the list after removing delete even numbers in [5,6,77,45,22,12,24].***
7+
8+
9+
----------------------
10+
### Hints
11+
> ***Use list comprehension to delete a bunch of element from a list.***
12+
13+
----------------------
14+
15+
**Main author's Solution: Python 2**
16+
```python
17+
li = [5,6,77,45,22,12,24]
18+
li = [x for x in li if x%2!=0]
19+
print li
20+
```
21+
----------------
22+
**My Solution: Python 3**
23+
```python
24+
#to be written
25+
26+
```
27+
---------------------
28+
29+
30+
31+
# Question 81
32+
33+
### **Question**
34+
35+
>***By using list comprehension, please write a program to print the list after removing delete numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155].***
36+
37+
----------------------
38+
### Hints
39+
> ***Use list comprehension to delete a bunch of element from a list.***
40+
41+
----------------------
42+
43+
**Main author's Solution: Python 2**
44+
```python
45+
li = [12,24,35,70,88,120,155]
46+
li = [x for x in li if x%5!=0 and x%7!=0]
47+
print li
48+
```
49+
----------------
50+
**My Solution: Python 3**
51+
```python
52+
#to be written
53+
54+
```
55+
---------------------
56+
57+
# Question 82
58+
59+
### **Question**
60+
61+
>***By using list comprehension, please write a program to print the list after removing the 0th, 2nd, 4th,6th numbers in [12,24,35,70,88,120,155].***
62+
63+
----------------------
64+
### Hints
65+
>***Use list comprehension to delete a bunch of element from a list.
66+
Use enumerate() to get (index, value) tuple.***
67+
68+
----------------------
69+
70+
**Main author's Solution: Python 2**
71+
```python
72+
73+
li = [12,24,35,70,88,120,155]
74+
li = [x for (i,x) in enumerate(li) if i%2!=0]
75+
print li
76+
```
77+
----------------
78+
**My Solution: Python 3**
79+
```python
80+
#to be written
81+
82+
```
83+
---------------------
84+
85+
86+
# Question 83
87+
88+
### **Question**
89+
90+
>***By using list comprehension, please write a program to print the list after removing the 0th, 2nd, 4th,6th numbers in [12,24,35,70,88,120,155].***
91+
92+
----------------------
93+
### Hints
94+
> ***Use list comprehension to delete a bunch of element from a list.
95+
Use enumerate() to get (index, value) tuple.***
96+
97+
----------------------
98+
99+
**Main author's Solution: Python 2**
100+
```python
101+
102+
li = [12,24,35,70,88,120,155]
103+
li = [x for (i,x) in enumerate(li) if i%2!=0]
104+
print li
105+
106+
```
107+
----------------
108+
**My Solution: Python 3**
109+
```python
110+
#to be written
111+
112+
```
113+
---------------------
114+
115+
116+
117+
# Question 84
118+
119+
### **Question**
120+
121+
>***By using list comprehension, please write a program generate a 3*5*8 3D array whose each element is 0.***
122+
123+
124+
----------------------
125+
### Hints
126+
> ***Use list comprehension to make an array.***
127+
128+
----------------------
129+
130+
**Main author's Solution: Python 2**
131+
```python
132+
133+
array = [[ [0 for col in range(8)] for col in range(5)] for row in range(3)]
134+
print array
135+
```
136+
----------------
137+
**My Solution: Python 3**
138+
```python
139+
#to be written
140+
141+
```
142+
---------------------
143+
144+

0 commit comments

Comments
 (0)