limit the integer between to 1000 and 2000
时间: 2024-04-13 07:29:06 浏览: 9
You can limit an integer between 1000 and 2000 using the following Python code:
```python
def limit_integer(num):
if num < 1000:
return 1000
elif num > 2000:
return 2000
else:
return num
# Example usage
num = 1500
limited_num = limit_integer(num)
print(limited_num)
```
This code defines a function `limit_integer()` that takes an integer as input and returns the integer limited between 1000 and 2000. If the input number is less than 1000, it returns 1000. If the input number is greater than 2000, it returns 2000. Otherwise, it returns the input number itself. In the example usage, the input number is 1500, so the output will be 1500 since it is within the desired range.