Here's a Python function named 'random_number' that returns a random number between 10 and 20:

import random

def random_number():
    return random.randint(10, 20)

# Example usage
result = random_number()
print(result)

In this code:

  1. We import the 'random' module, which offers various functions for generating random numbers.
  2. The 'random_number' function uses the 'randint' function from the 'random' module. 'randint' generates a random integer within the specified range (inclusive), in this case, between 10 and 20.
  3. The function returns the generated random number.

You can test the function by calling it and printing the result as shown in the example usage. Each time you run the code, it will produce a different random number between 10 and 20.

Python Function to Generate Random Numbers Between 10 and 20

原文地址: http://www.cveoy.top/t/topic/bv1f 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录