0

How to add a item in list taking user input

appending elements in tuple

30th Sep 2018, 2:51 AM
Umesh Tikhe
Umesh Tikhe - avatar
5 Answers
0
x = input() list =["hello", "darkness", x] print(list)
30th Sep 2018, 3:47 AM
Hayden
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!
30th Sep 2018, 8:55 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
using loop
1st Oct 2018, 6:47 AM
Umesh Tikhe
Umesh Tikhe - avatar
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".
1st Oct 2018, 9:17 AM
Kishalaya Saha
Kishalaya Saha - avatar
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)
1st Oct 2018, 10:26 AM
Umesh Tikhe
Umesh Tikhe - avatar