+ 14

How to provide dynamic range value?

lst=[] for i in range(0,): lst.append(input())

24th Aug 2019, 7:17 PM
Ozair Khan
Ozair Khan - avatar
5 Respuestas
+ 9
n = int(input()) lst = [] for _ in range(0, n): lst.append(input())
24th Aug 2019, 7:20 PM
Burey
Burey - avatar
+ 9
You can put the code in a while loop and add another input which asks the user if he'd like to input another value Or, alternatively define a 'stop value' which will break the loop if the condition is met
24th Aug 2019, 7:43 PM
Burey
Burey - avatar
+ 8
Burey I mean without providing range Like in C dynamic memory allocation Memory is increased as values are added. But here we cannot append after n.
24th Aug 2019, 7:31 PM
Ozair Khan
Ozair Khan - avatar
+ 3
Maybe this helps? Built this little guy the other day, your post made me think of it EDIT: haven't tried the input method with it yet... https://code.sololearn.com/cqbZK7wU8zLQ/?ref=app
25th Aug 2019, 12:04 AM
Steven M
Steven M - avatar
+ 2
Can you please show a c code so that we can figure what kind of behavior you want to have in python?
24th Aug 2019, 10:39 PM
Théophile
Théophile - avatar