Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 351: 10.10

Answer

code

Work Step by Step

# 10.10 (Reverse a list) The reverse function in Section 10.8 reverses a list by copying it # to a new list. Rewrite the function that reverses the list passed in the argument and # returns this list. Write a test program that prompts the user to enter a list of numbers, # invokes the function to reverse the numbers, and displays the numbers. def reverse(lst): for i in range(len(lst)//2): lst[i], lst[len(lst) - 1 - i] = lst[len(lst) - 1 - i], lst[i] def main(): lst = input("Enter numbers: ").split() lst = [int(x) for x in lst] reverse(lst) print(lst) main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.