Random.randint() missing 2 required positional arguments: 'a' and 'b'
时间: 2024-01-23 09:04:13 浏览: 248
python中random.randint和random.randrange的区别详解
5星 · 资源好评率100%
This error occurs when you call the `randint()` function from the `random` module without providing the two required arguments `a` and `b`.
The `randint()` function generates a random integer between two values `a` and `b`, inclusive. Therefore, you need to provide the values of `a` and `b` to the function to specify the range of possible values.
Here is an example of how to use the `randint()` function correctly:
```
import random
# Generate a random integer between 1 and 10
random_number = random.randint(1, 10)
print(random_number)
```
In this example, the `randint()` function is called with the arguments `1` and `10`, which specify the range of possible values for the generated integer. The function returns a random integer between `1` and `10`, inclusive, and assigns it to the variable `random_number`. The generated number is then printed to the console.
阅读全文