Python Forum
Bingo Ticket Question
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bingo Ticket Question
#1
Would anyone be able to help me out with this question I have been set, I am very new to Python and do not know much about arrays however I know that Python uses lists instead. I just do not know how to apply them to this question at all and where I would start, I would really appreciate if someone would break down the steps into approaching this question so I can attempt to answer it myself with the steps you provided, thank you very much. Here is the question:

A printing company uses a computer program to randomly generate and print bingo tickets. Each bingo ticket has a grid with three rows and nine columns. Each row contains 5 numbers and 4 blank spaces. The computer program stores the numbers in a 2-dimensional array called Ticket. In the array Ticket, the first index represents the row and the second represents the column. e.g. Ticket(1,4) = 32 means the number on row 1, column 4 is 32.

To generate the tickets, the computer program first fills in the columns with random integers. After filling the array, the computer program ensures that no numbers have been repeated, and replaces four positions on each row with the number 0.

A bingo ticket is printed using the following method.
For every row in the array
For every column in that row
— If the value is o then output a space
— otherwise output the value
Write an algorithm to print the numbers in the array onto a ticket. You should indent your code correctly to make it easier to understand.



Thank you,

-Oli
Reply
#2
The easiest way to start, is to start at the easiest part.  In this case, that'd be with a hard-coded ticket, and write a function which can print it out.  Once that's done, write a function which can generate a random ticket.  Stick the pieces together, and you're done :)
Reply
#3
Here's a session in the console that might help you somewhat:

mycomputer:@18:20:51:~/pythonscratch $ python
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> table = [[23,43,16,68], [12,45,22,91], [87,48,15,12]]
>>> for row in table:
...     print(row)
...
[23, 43, 16, 68]
[12, 45, 22, 91]
[87, 48, 15, 12]
>>> for row in table:
...     for cell in row:
...             print(cell)
...
23
43
16
68
12
45
22
91
87
48
15
12
I am trying to help you, really, even if it doesn't always seem that way
Reply
#4
Thank you, I understand this now :)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020