0
How to add a item in list taking user input
appending elements in tuple
5 Answers
0
x = input()
list =["hello", "darkness", x]
print(list)
0
Is it list, or tuple?
For list:
a = ["Python", "C"]
a.append(input())
For tuple: (Tuples are immutable, so we can't technically append to them. The following builds a new tuple by combining the old one and the input, and give it the same name.)
a = ("Python", "C")
a += (input(),)
Don't miss the comma in the second line!
0
using loop
0
Method 1: First make the user enter n, the number of inputs. Then just do a for loop with range(n).
Method 2: use a while True condition. Break the loop when the user enters a special keyword, like "end".
0
I got the ans
a=[]
def addElement():
x=input('enter the element: ')
while x!='' :
a.append(x)
c=input('if you want to enter a another account press y')
if c=='y' :
addElement()
else:
print(a)
addElement()
print(a)