CBSE Class 12 Computer Science Question 27 of 57

Review of Python Basics — Question 27

Back to all questions
27
Question

Question 22

Write a program to accept values from a user in a tuple. Add a tuple to it and display its elements one by one. Also display its maximum and minimum value.

Solution
tuple1 = eval(input("Enter a tuple: "))
tuple2 = (10, 20, 30)
combined_tuple = tuple1 + tuple2
print("Elements of the combined tuple:")
for element in combined_tuple:
    print(element)

print("Maximum value:", max(combined_tuple))
print("Minimum value:", min(combined_tuple))
Output
Enter a tuple: (11, 67, 34, 65, 22)
Elements of the combined tuple:
11
67
34
65
22
10
20
30
Maximum value: 67
Minimum value: 10
Answer

tuple1
=
eval
(
input
(
"Enter a tuple: "
))
tuple2
=
(
10
,
20
,
30
)
combined_tuple
=
tuple1
+
tuple2
print
(
"Elements of the combined tuple:"
)
for
element
in
combined_tuple
:
print
(
element
)
print
(
"Maximum value:"
,
max
(
combined_tuple
))
print
(
"Minimum value:"
,
min
(
combined_tuple
))
Output
Enter a tuple: (11, 67, 34, 65, 22)
Elements of the combined tuple:
11
67
34
65
22
10
20
30
Maximum value: 67
Minimum value: 10