Python - Write a for loop to display a given number in reverse -
this question has answer here:
how have user input number , have computer spit number out in reverse?
num = int(input("insert number of choice ")) in
that have far... using 3.3.4
you don't need make int , again make str! make straight this:
num = input("insert number of choice ") print (num[::-1])
or, try using loop:
>>> rev = '' >>> in range(len(num), 0, -1): ... rev += num[i-1] >>> print(int(rev))
best way loop on python string backwards says efficient/recommended way be:
>>> c in reversed(num): ... print(c, end='')
Comments
Post a Comment