55
66> *** Please write a program to randomly print a integer number between 7 and 15 inclusive.***
77
8-
98----------------------
109### Hints
1110> *** Use random.randrange() to a random integer in a given range.***
1211
1312----------------------
1413
15- ** Main author's Solution: Python 2 **
14+ ** Solution:**
1615``` python
1716import random
1817print random.randrange(7 ,16 )
1918```
2019----------------
21- ** My Solution: Python 3**
22- ``` python
23- # to be written
24-
25- ```
26- ---------------------
27-
28-
2920
3021# Question 76
3122
@@ -39,7 +30,7 @@ print random.randrange(7,16)
3930
4031----------------------
4132
42- ** Main author's Solution: Python 2 **
33+ ** Solution:**
4334``` python
4435import zlib
4536s = ' hello world!hello world!hello world!hello world!'
@@ -48,12 +39,6 @@ print t
4839print zlib.decompress(t)
4940```
5041----------------
51- ** My Solution: Python 3**
52- ``` python
53- # to be written
54-
55- ```
56- ---------------------
5742
5843# Question 77
5944
@@ -77,12 +62,28 @@ print t.timeit()
7762----------------
7863** My Solution: Python 3**
7964``` python
80- # to be written
81-
65+ import datetime
66+
67+ before = datetime.datetime.now()
68+ for i in range (100 ):
69+ x = 1 + 1
70+ after = datetime.datetime.now()
71+ execution_time = after - before
72+ print (execution_time.microseconds)
73+ ```
74+ ** OR**
75+ ``` python
76+ import time
77+
78+ before = time.time()
79+ for i in range (100 ):
80+ x = 1 + 1
81+ after = time.time()
82+ execution_time = after - before
83+ print (execution_time)
8284```
8385---------------------
8486
85-
8687# Question 78
8788
8889### ** Question**
@@ -107,12 +108,23 @@ print li
107108----------------
108109** My Solution: Python 3**
109110``` python
110- # to be written
111+ import random
111112
113+ lst = [3 ,6 ,7 ,8 ]
114+ random.shuffle(lst)
115+ print (lst)
112116```
113- ---------------------
114-
117+ ** OR**
118+ ``` python
119+ import random
115120
121+ # shuffle with a chosen seed
122+ lst = [3 ,6 ,7 ,8 ]
123+ seed = 7
124+ random.Random(seed).shuffle(lst)
125+ print (lst)
126+ ```
127+ ---------------------
116128
117129# Question 79
118130
@@ -142,8 +154,14 @@ for i in range(len(subjects)):
142154----------------
143155** My Solution: Python 3**
144156``` python
145- # to be written
157+ subjects= [" I" , " You" ]
158+ verbs= [" Play" , " Love" ]
159+ objects= [" Hockey" ," Football" ]
146160
161+ for sub in subjects:
162+ for verb in verbs:
163+ for obj in objects:
164+ print (" {} {} {} " .format(sub,verb,obj))
147165```
148166---------------------
149167
0 commit comments