Table of Contents

Find Maximum Minimum Number from User Input

Example Description
This program takes n numbers as input from the user and stores them in a tuple, then prints the maximum and minimum numbers from the tuple.

Introduction:

This Python program takes user input for n numbers and stores them in a tuple. It then finds and prints the maximum and minimum numbers from the tuple.

Code:

#Program to input n numbers from the user. Store these numbers 
#in a tuple. Print the maximum and minimum number from this tuple.
numbers = tuple() #create an empty tuple 'numbers'
n = int(input("How many numbers you want to enter?: "))
for i in range(0,n): 
 num = int(input())
 #it will assign numbers entered by user to tuple 'numbers'
 numbers = numbers +(num,) 
print('\nThe numbers in the tuple are:')
print(numbers)
print("\nThe maximum number is:")
print(max(numbers))
print("The minimum number is:")
print(min(numbers))

Logic:

  1. Create an empty tuple ‘numbers’.
  2. Take input from the user for the number of numbers (n) they want to enter.
  3. Use a for loop to iterate ‘n’ times and take input for each number from the user.
  4. Assign the entered numbers to the tuple ‘numbers’ using the tuple concatenation operation.
  5. Print the numbers stored in the tuple.
  6. Find and print the maximum and minimum numbers from the tuple using the max() and min() functions.

Output:

How many numbers you want to enter?: 5

10

15

20

25

30

>>

>> The numbers in the tuple are:

>> (10, 15, 20, 25, 30)

>>

>> The maximum number is:

>> 30

>> The minimum number is:

>> 10