Write a program to input ‘n’ numbers and store it in tuple.
Answers
Answered by
17
Answer:
Explanation:
t = tuple ( )
n = input (“Enter any number”)
print “Enter all numbers one after other”
for i in range (n) :
a = input (“Enter number”)
t = t+(a, )
print “Output is”
print t
Answered by
2
# python program for storing n elements in a tuple
required_tuple = tuple()
number_of_element = int(input('Number of elements: '))
for i in range(number_of_element):
element = int(input('Enter number: '))
required_tuple +5= (element,)
print('stored tuple is: ', required_tuple)
- 1st line creates a variable of tuple type, empty, where we will store n numbers provided by user.
- 2ed line creates a variable of integer type, taking input from the user, which will be the required n.
- 3rd line is a for loop with range n to run the whole process n times, each time it takes a number as input adds it to tuple and goes all over again.
- Last we print the stored tuple.
Similar questions
Math,
5 months ago
Chemistry,
5 months ago
English,
5 months ago
Computer Science,
9 months ago
Computer Science,
9 months ago