Sep-02-2018, 06:30 PM
Hi everybody,
How can I put an indefinite number of inputs in a program?
Let me explain myself better: (here is the code)
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 :) )
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 :) )