---71---
Question:
>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.
Hints:
>Use random.choice() to a random element from a list.
Solution:
![](https://img.haomeiwen.com/i22440010/6894c9a2e1d741d6.png)
![](https://img.haomeiwen.com/i22440010/6d2f6b3e6fa0b6ac.png)
----72---
Question:
>Please write a program to generate a list with 5 random numbers between 100 and 200 inclusive.
Hints:
>Use random.sample() to generate a list of random values.
Solution:
![](https://img.haomeiwen.com/i22440010/b5fedbd37b85b003.png)
![](https://img.haomeiwen.com/i22440010/6751f68418af03a2.png)
---73---
Question:
>Please write a program to randomly generate a list with 5 even numbers between 100 and 200 inclusive.
Solution:
解法一
![](https://img.haomeiwen.com/i22440010/b1a0d5e3838e8fd5.png)
![](https://img.haomeiwen.com/i22440010/d9cc14ead51ca91f.png)
解法二
![](https://img.haomeiwen.com/i22440010/23cf08cb91802af0.png)
![](https://img.haomeiwen.com/i22440010/61a52e7a9237adef.png)
---74---
Question:
>Please write a program to randomly generate a list with 5 numbers, which are divisible by 5 and 7 , between 1 and 1000 inclusive.
Solution:
![](https://img.haomeiwen.com/i22440010/4a7ac66412fa30eb.png)
![](https://img.haomeiwen.com/i22440010/71e1c8ff821fc021.png)
---75---
Question:
>Please write a program to randomly print a integer number between 7 and 15 inclusive.
Hints:
>Use random.randrange() to a random integer in a given range.
Solution:
![](https://img.haomeiwen.com/i22440010/d7bd74d2fd472fcb.png)
![](https://img.haomeiwen.com/i22440010/47826a1f22a18752.png)
网友评论