The following image shows 4 boxes containing different balls labelled by numbers between 1 and 9. COUN 8 (7) 5 2 (8 The boxes are used in a lottery to determine a winning combination of 4 numbers by drawing one ball from each box. To enter the lottery, participants write 4 numbers between 1 and 9 on their ticket in nondecreasing order (from smallest to largest). A ticket wins if all its numbers are drawn in the lottery. The order in which the numbers are drawn does not matter. For example, if the drawing is (2, 8, 2, 1), then a ticket with the numbers (1, 2, 2, 8) wins (the numbers are the same, albeit in a different order), but a ticket with the numbers (1, 2, 2, 9) loses. Construct a list of all valid tickets, i.e., all tickets that can potentially be drawn in the lottery, and store it in the variable possible_tickets. The tickets should be specified as tuples of 4 numbers in nondecreasing order, and every valid ticket should appear exactly one time in the list possible_tickets. (Note, however, that some numbers may occur more than once on a single ticket, as in the above example.) Answer: (penalty regime: 0, 0, 0, 0, 50, 50 %) 1 import itertools 2 3 # Generate all possible combinations of 4 numbers between 1 and 9 in non-decreasing order 4 possible_tickets list(itertools.combinations_with_replacement(range(1, 10), 4)) 5 = 6 # Sort each ticket in non-decreasing order 7 possible_tickets = [tuple(sorted(ticket)) for ticket in possible_tickets] 8 9 # Remove duplicate 10 possible_tickets = list(set(possible_tickets)) 11 tickets 12 # Sort the list of tickets 13 possible_tickets.sort()

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

Hi I need help with this question please, my code failed the test.

The following image shows 4 boxes containing different balls labelled by numbers between 1 and 9.
COUN
8
(7)
5
2 (8
The boxes are used in a lottery to determine a winning combination of 4 numbers by drawing one ball from each box. To enter the lottery, participants write 4
numbers between 1 and 9 on their ticket in nondecreasing order (from smallest to largest). A ticket wins if all its numbers are drawn in the lottery. The order in which
the numbers are drawn does not matter.
For example, if the drawing is (2, 8, 2, 1), then a ticket with the numbers (1, 2, 2, 8) wins (the numbers are the same, albeit in a different order), but a
ticket with the numbers (1, 2, 2, 9) loses.
Construct a list of all valid tickets, i.e., all tickets that can potentially be drawn in the lottery, and store it in the variable possible_tickets. The tickets should be
specified as tuples of 4 numbers in nondecreasing order, and every valid ticket should appear exactly one time in the list possible_tickets. (Note, however, that some
numbers may occur more than once on a single ticket, as in the above example.)
Answer: (penalty regime: 0, 0, 0, 0, 50, 50 %)
1 import itertools
2
3 # Generate all possible combinations of 4 numbers between 1 and 9 in non-decreasing order
4 possible_tickets list(itertools.combinations_with_replacement(range(1, 10), 4))
5
=
6 # Sort each ticket in non-decreasing order
7
possible_tickets = [tuple(sorted(ticket)) for ticket in possible_tickets]
8
9 # Remove duplicate
10 possible_tickets = list(set(possible_tickets))
11
tickets
12 # Sort the list of tickets
13
possible_tickets.sort()
Transcribed Image Text:The following image shows 4 boxes containing different balls labelled by numbers between 1 and 9. COUN 8 (7) 5 2 (8 The boxes are used in a lottery to determine a winning combination of 4 numbers by drawing one ball from each box. To enter the lottery, participants write 4 numbers between 1 and 9 on their ticket in nondecreasing order (from smallest to largest). A ticket wins if all its numbers are drawn in the lottery. The order in which the numbers are drawn does not matter. For example, if the drawing is (2, 8, 2, 1), then a ticket with the numbers (1, 2, 2, 8) wins (the numbers are the same, albeit in a different order), but a ticket with the numbers (1, 2, 2, 9) loses. Construct a list of all valid tickets, i.e., all tickets that can potentially be drawn in the lottery, and store it in the variable possible_tickets. The tickets should be specified as tuples of 4 numbers in nondecreasing order, and every valid ticket should appear exactly one time in the list possible_tickets. (Note, however, that some numbers may occur more than once on a single ticket, as in the above example.) Answer: (penalty regime: 0, 0, 0, 0, 50, 50 %) 1 import itertools 2 3 # Generate all possible combinations of 4 numbers between 1 and 9 in non-decreasing order 4 possible_tickets list(itertools.combinations_with_replacement(range(1, 10), 4)) 5 = 6 # Sort each ticket in non-decreasing order 7 possible_tickets = [tuple(sorted(ticket)) for ticket in possible_tickets] 8 9 # Remove duplicate 10 possible_tickets = list(set(possible_tickets)) 11 tickets 12 # Sort the list of tickets 13 possible_tickets.sort()
Expert Solution
steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning