Programs · Program 10-4
Q.Program 10-4: Write a program to input n numbers from the user. Store these numbers in a tuple. Print the maximum and minimum number from this tuple.
Rajasthan RbseTextbookSubjective· 3mImportance★★★★★est
23% · 7/30 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Grow the tuple with numbers = numbers + (num,) inside the input loop, then let the built-ins max() and min() report the largest and smallest values.
The idea. Two standard tuple techniques combine here. First, because a tuple cannot be appended to, each new number is wrapped as the one-element tuple (num,) and concatenated — producing a new tuple each pass. Second, finding extremes needs no manual comparison loop: max() and min() accept any sequence.
Program 10-4:
numbers = ()
n = int(input("How many numbers do you want to enter?: "))
for i in range(n):
num = int(input("Enter number: "))
numbers = numbers + (num,) # concatenation builds a new, longer tuple
print("The numbers in the tuple are:", numbers)
print("Maximum number:", max(numbers))
print("Minimum number:", min(numbers))
Sample run:
How many numbers do you want to enter?: 5
Enter number: 40
Enter number: 12
Enter number: 56
Enter number: 27
Enter number: 3
The numbers in the tuple are: (40, 12, 56, 27, 3)
Maximum number: 56
Minimum number: 3
Key lines: …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.