+ 1
Hello. Python
How do i write a funcion where if given number does not end in 0 it would rrturn itin the oposite order. Can only use int. Ex. 1024 return 4201
5 Réponses
+ 3
Try this code.
def g(x):
if(str(x)[-1]!='0'):
return int(str(x)[::-1])
print(g(123)) #output=321
+ 2
Benny Kosasih now check my new answer you will get your answer.why you got weird output.
+ 1
convert the number to an array of digits, reverse the order and convert the array to a number.
+ 1
Tested Maninder $ingh code, it gives weird result, some number with 0 gone, some stayed the same like 1000 become 0001.
https://code.sololearn.com/cEVO79BK3Sgv/?ref=app
+ 1
Benny Kosasih brother you are passing a list in function so for loop is require for every number now check my code.my old code only work with single number not with list of number now you can also work with list of numbers.
https://code.sololearn.com/cKO0U6IVgdwl/?ref=app