**Python code to find bugs (12) **
**Code design requirements of the previous period: **
Generate a random number between 10 and 20.
code show as below:
Please read the code carefully to find out the bugs!
**Correct answer: There are 2 questions. **
(1) Random is a module in the Python3 standard library. When quoting, you only need to directly use the import keyword to import it. If the from keyword is used, it should be used in conjunction with import.
(2) Another error is the use of random seed() function. The seed() function does not return a random number, but determines whether the seed of the random number is fixed. The random.uniform(a,b) function should be used to generate random numbers in the specified interval, where a and b are the lower and upper limits of the interval.
So, the correct code should look like this:
**Comments: **
(1) Consolidate the usage of module import.
(2) Familiar with and understand the basic methods of creating random numbers.
(3) The questions in this issue seem simple, but they are actually very important. Especially with regard to the random number generation method, the usage of the random module in Python not only includes how to generate random numbers in a specified interval, but also generates random integers, random decimals, and generates the same or different random numbers multiple times in the same interval Functions and methods of counting. It is recommended that interested students study it in depth and incorporate this knowledge point into their knowledge base.
Recommended Posts