Please write and explain the coding for the given python pattern(using while loop). | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please write and explain the coding for the given python pattern(using while loop).

8642 864 86 8

10th Sep 2019, 8:35 AM
Yash Garg
Yash Garg - avatar
1 Answer
0
i = 0 n = "8642" while len(n) != 0: print(n) n = n[0: len(n[:-1])] You proceed the number as a string. Strings are sliceable. The orientation is the lenght of the string. Take the rules of slicing and iterate it until the len of the given string is 0. Edit: https://code.sololearn.com/ca1FVvy5qmwW/?ref=app with comments Sorry, it is hard to explain for me. Maby you train slicing, then you will get it.
10th Sep 2019, 5:43 PM
Sven_m
Sven_m - avatar