0

Using a nested for loop in python

Print: 86420 02468 86420 02468 My code: num = '86420' reverse = ' ' for x in range (len(num), 0, -1): for y in range (len(num), 0, -1): reverse +=num[a-1] print(reverse) print()

22nd Feb 2022, 1:44 AM
Jaz
Jaz - avatar
4 odpowiedzi
+ 3
num = '86420' for x in range ( len( num ) ): print( num ) num = num[ : : -1 ]
22nd Feb 2022, 1:53 AM
Ipang
+ 1
using list comprehension [print("86420"[::-1] if i%2 else "86420") for i in range(4)]
22nd Feb 2022, 3:51 AM
Simba
Simba - avatar
0
num='Abhishek kumar' reverese=num[::-1] print(reverese) a=len(num) b='' for x in range(a-1,-1,-1): b=b+num[x] print(b)
22nd Feb 2022, 3:21 AM
Abhishek Kumar
Abhishek Kumar - avatar