(Feb-02-2019, 07:51 PM)sonedap Wrote: How can i change it so the printing isn't [range(1,5)] etc but the numbers?
Query:Why simple exercises are so difgicult in their solution??
Solution is not difficult. You just need to articulate what you want to do. Can you say in spoken language what your code should do? Unambiguously? So that other person can understand?
You are in right track, but your range is not correct. You want growing range, so you should use i+1 as end of range (range(1, 2) --> 1, range(1, 3) --> 1, 2 etc.
One way to achieve desired results using list comprehension:
>>> [list(range(1, i+1)) for i in range(1, 5)] [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]Another way is to correct your code:
>>> result = list() >>> for i in range(1, 5): ... result.append(list(range(1, i+1))) ... >>> result [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]I just mention that this is Python 3.
(Feb-02-2019, 10:08 PM)sonedap Wrote: And now i am wondering why i am trying to learn python since i am not good.
Don't give up so easily. It takes time. I suggest you to read this: Teach Yourself Programming in Ten Years. You probably don't know who Peter Norvig dude is, so you can read about him in Wikipedia.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.