Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

AutoSave A HW7 - Saved to this PC- Scarch Johnson, Gunnar K. G File Home Insert Draw Design Layout References Mailings Review View Help Share

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

AutoSave A HW7 - Saved to this PC- Scarch Johnson, Gunnar K. G File Home Insert Draw Design Layout References Mailings Review View Help Share Comments = = [ X cut [Copy Format Painter Clipboard Cambria (Headin - 15 - A A Aar BIUX, * A-D-A- Peste AaBb codi AaBb Abbccod Aabbccod AaBbcc AaBbccc AaB Heading 1 1 Nomal 1 No Spac. Heading 2 Heading 3 Code Title Find Replace Select Editing Dictate Sensitivity Font Paragraph Styles Voice Sensbury Homework 7 - A Visit to the Horse Races for this assignment, you will simulate a horse race, making use of randorn numbers and random selection, storing data in lists and list of lists. This program will create a list of unique random numbers for the horses, then prompt the user to enter names for each harse. The list of horse numbers & names will be displayed, then the race run. The program will randomly select three of the horses as the first second and third place winners, and display them. Function main will do minimal work-own the data lists that get passed around, print some messages, and call the functions below to do the major work Functions You will write the following four functions, besides main): senhorst.juma given the number of horses and the largest valid number, creates a list of random integers in the range 1 to largest, inclusive. Ensures there are no duplicates. Returns the list set.horse Dames display_horses given the list of horse numbers, prompts the user with the number, gets a name, builds a list with number & name sublists, Sorts the list based on horse number. . . Returns the new list given the list of horse number & name pairs, displays them in the format shown in sample below. Format the number in two column space, then two blank , spaces before the name given the list of horse number & and name pairs, selects three pairs as first, second and third place. Creates list with the three selected pairs, ensuring no duplications. Returns the winner list calls ren herse.nums to get list of numbers. Use 5 horses, 20 as largest number. Than elle est bara smeta il in the ser call direla barrets chours pick.winners main Page 1 of 2 645 words Focus EL Type here to search - + 1004 1:33 PM 3/3/2021 O Pi W 40 AutoSave A HW7 - Saved to this PC- Scarch Johnson, Gunnar K. G File Home Insert Draw Design Layout References Mailings Review View Help Share Comments 4 AaBbc.codi AaBbc Aabbccod Aabbccod Aabbcc Aabbccc AaB X cut [Copy Format Painter Clipboard Cambria (Headin - 16 A A A BIUX, * A-D-A- Peste FH Code Heading 1 Normal 1 No Spac. Heading 2 Heading 3 Title Find Replace Select Editing Dictate Sensitivity Fort Voice Sensbury Paragraph Styles duplications. Returns the winner list main calls cenborse.nums to get list of numbers. Use 5 horses, 20 as largest number. Then calls get horse Dames to fill in the names. Calls display.horses to show all the horses, announces the race start, calls pick winners, calls display_horses again to show the winning horses. For each function, be sure to have the correct parameter(s) and return values (if needed). Ensuring a list is all unique While it's unlikely that the same number will come up when generating the random numbers for the horses, or when picking the winners, it's possible. So you should generate the number/choice before adding to the list, check that the value doesn't already exist. If it's not found, add it. This is a good time to use the not in operator Sorting Since you are sorting a list of lists based on the first element in each sublist, you don't have to do anything special Random Numbers and Selection Using the random module (import random), the two functions you ought to use are ca dintul and chuice randintl) takes two arguments, starting and ending numbers. It will retum an interer such that start

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is meant by a cash flow waterfall?

Answered: 1 week ago

Question

Sample ciphertext...

Answered: 1 week ago