Infinite # of inputs - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Infinite # of inputs (/thread-12599.html) |
Infinite # of inputs - Hermann_Fegelein - Sep-02-2018 Hi everybody, How can I put an indefinite number of inputs in a program? Let me explain myself better: (here is the code) '''ex 8 def multiplier(items): multiplied=[] multiplied=[item*2 for item in items] return(multiplied) try: number1=int(input("Insert 5 numbers (1st): ")) number2=int(input("Insert 5 numbers (2nd): ")) number3=int(input("Insert 5 numbers (3rd): ")) number4=int(input("Insert 5 numbers (4th): "))until a precise input, (I.E: "stop")? For example, user Jimmy inserts: print(multiplier([number1, number2, number3, number4])) except ValueError: print("insert a number!") '''How can I make the program accept as many inputs as the user wants until a precise input, for example ("stop")? Another pretty straight-forward example: 2, 4, 8, 4, -3, "stop" The program will multiply (in this case) 2, 4, 8, 4 and -3. I don't know if I made this clear enough tho, sorry. Anyway, thanks in advance for your kind help! ( Oh, and if you could tell me how to improve the code in general, that'd be appreciate :) ) RE: Infinite # of inputs - woooee - Sep-02-2018 Use a while ## meant to be an example only user_input="" while user_input.lower() != "stop": user_input=input("Enter another number ") print(user_input) |