Here I am back with a new challenge for you guys.
Lets try to create a logic sequence of number in Python. Look at the below image.
The above logic sequence is created using following keywords:
- List
- Nested For Loop
- Print (of course)
Try to analyze the above given data and create the sequence from your own.
Failed? Click More below to get the Solution…
Here is the solution. Python Code file is attached at the end of the article.
list=[]
for i in range(0,7):
list.append(1)
for j in range(1,i):
list[j]=0
print(list)
If you have any queries, more simplified programs or solutions then kindly comment below. Also you can Email me your doubts and queries related to program.
Thank You!
Attachment: Number_Sequence.py
>>> for x in range(7):
… print([1 if i in [0,x-1] else 0 for i in range(x)])
…
[]
[1]
[1, 1]
[1, 0, 1]
[1, 0, 0, 1]
[1, 0, 0, 0, 1]
[1, 0, 0, 0, 0, 1]
LikeLiked by 1 person
first line should be:
>>> for x in range(1,7):
LikeLike
What u r asking for?
LikeLike
if i replace it with my code than it wont return the expected results
LikeLike
thanx for sharing this method…
this one is the most simplicit one…
LikeLike