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.11

Answer

code

Work Step by Step

# 10.11 (Random number chooser) You can shuffle a list using random.shuffle(lst). # Write your own function without using random.shuffle(lst) to shuffle a list # and return the list. Use the following function header: # def shuffle(lst): # Write a test program that prompts the user to enter a list of numbers, invokes the # function to shuffle the numbers, and displays the numbers. import random def shuffle(lst): for q in range(len(lst)): i, p = random.randint(0, len(lst)-1), random.randint(0, len(lst)-1) lst[i], lst[p] = lst[p], lst[i] def main(): lst = input("Enter numbers: ").split() lst = [int(x) for x in lst] shuffle(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.