import random
N = int(input("Enter the number of elements in the list: "))
# create a list of N random integers between 1 and 50
numbers = [random.randint(1, 50) for i in range(N)]
print("The created list is: ", numbers)
# find the maximum and minimum elements in the list
maximum = max(numbers)
minimum = min(numbers)
print("The maximum element is: ", maximum)
print("The minimum element is: ", minimum)
# calculate the difference between the maximum and minimum elements
difference = maximum - minimum
print("The difference between the maximum and minimum elements is: ", difference)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
import random
N = int(input("Enter the number of elements in the list: "))
# create a list of N random integers between 1 and 50
numbers = [random.randint(1, 50) for i in range(N)]
print("The created list is: ", numbers)
# find the maximum and minimum elements in the list
maximum = max(numbers)
minimum = min(numbers)
print("The maximum element is: ", maximum)
print("The minimum element is: ", minimum)
# calculate the difference between the maximum and minimum elements
difference = maximum - minimum
print("The difference between the maximum and minimum elements is: ", difference)