In: Computer Science
reverse_number_in_list(number_list:list)-> list
This function will be given a list of numbers your job is to
reverse all the numbers in the list and return a list with the
reversed numbers. If a number ends with 0 you need to remove all
the trailing zeros before reversing the number. An example of
reversing numbers with trailing zeros: 10 -> 1, 590 -> 95.
None of the numbers in the number_list will be less than 1.
Example:
number_list = [13, 45, 690, 57]
output = [31, 54, 96, 75]
Please look at my code and in case of indentation issues check the screenshots.
------------main.py-----------------
def reverse_number_in_list(number_list):
output_list = []
#output
list
for number in number_list:
#read each number from the
input list
numberString =
str(number)
#convert number into
string
reverseNumberString =
numberString[::-1] #reverse the string
reverseNumber =
int(reverseNumberString) #convert string to
number
output_list.append(reverseNumber)
#append number to the output_list
return output_list
#return
the output list
#Test case 1
List1 = [13, 45, 690, 57]
print("Input: ", List1)
print("Reverse: ", reverse_number_in_list(List1))
#Test case 2
List2 = [23000, 4539, 80000]
print("\nInput: ", List2)
print("Reverse: ", reverse_number_in_list(List2))
--------------Screenshots-------------------
----------------------Output------------------------------------
-------------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs
down.
Please Do comment if you need any clarification.
I will surely help you.
Thankyou