I've been trying to figure out how to do bingo cards in python. I just learned about def functions and required to use them within my code. The point of this program is to Write a program that will create from 1 to n Bingo cards where n is some integer between 1 and 10. Each Bingo card consists of 5 columns and every column has a unique set of numbers for a given range. The ranges consist of the following: B – integers from 1 to 15 I – integers from 16 to 30 N – integers from 31 to 45 G – integers from 46 to 60 O – integers from 61 to 75 Each card is to be displayed with the BINGO heading along with 5 rows consisting of 5 B’s, 5 I’s, 4 N’s, 5 G’s and 5 O’s. There are only 4 N’s because the third row of the N column should display two dashes to indicate the free space on the card. What I have so far is this.
import random
GET_CARDNUMS = int(input('Enter the number of Bingo cards to generate (1-10): '))
def main():
get_cardnums()
generate_nums()
sort_nums()
def get_cardnums():
while True:
get_cardnums in range (GET_CARDNUMS)
if GET_CARDNUMS <= 10:
break
else:
print ('Enter the number of Bingo cards to generate (1-10): ')
break
print()
def generate_nums():
minB = 1
maxB = 15
for B in range (5):
B = random.randint (minB, maxB)
print (B)
minI = 16
maxI = 30
for I in range (5):
I = random.randint (minI, maxI)
print (f'I{I}')
minN = 31
maxN = 45
for N in range (4):
N = random.randint (minN, maxN)
print (f'N{N}')
minG = 46
maxG = 60
for G in range (5):
G = random.randint (minG, maxG)
print (f'G{G}')
minO = 61
maxO = 75
for O in range (5):
O = random.randint (minO, maxO)
print (f'O{O}')
def sort_values():
main ()
I was trying to look up lists and sorting functions because he said it would be helpful in creating rows but I just can not figure out how to set it up. Also sorry for the f-strings. I was trying to figure out how to print B, I, N, G, and O just as a single letter at the top of the randomly generated number but it seems just to end up outputting 5 B's for each random number, 5 I's for each random number, and so forth. Should I just print each letter separately for each number? like B1= B2= B3=. When looking it up many people were saying to use dictionary but I have not learned that yet so I'd want to stay away from that.
edit:
import random
GET_CARDNUMS = int(input('Enter the number of Bingo cards to generate (1-10): '))
def main():
get_cardnums()
generate_nums()
sort_nums()
def get_cardnums():
while True:
get_cardnums in range (GET_CARDNUMS)
if GET_CARDNUMS <= 10:
break
else:
print ('Enter the number of Bingo cards to generate (1-10): ')
break
print()
def generate_nums():
B = sorted(random.sample(range(1, 16), 5))
I = sorted(random.sample(range(16, 31), 5))
N = sorted(random.sample(range(31, 46), 4))
G = sorted(random.sample(range(46, 61), 5))
O = sorted(random.sample(range(61, 76), 5))
def sort_nums():
print (' B I N G O ')
print (f' {B:>3} {I:>3} {N:>3} {G:>3} {O:>3}')
print (f' {B:>3} {I:>3} {N:>3} {G:>3} {O:>3}')
print (f' {B:>3} {I:>3} --- {G:>3} {O:>3}')
print (f' {B:>3} {I:>3} {N:>3} {G:>3} {O:>3}')
print (f' {B:>3} {I:>3} {N:>3} {G:>3} {O:>3}')
main ()
Currently, my code will prompt with an error saying B I N G O is not defined. I'm not sure how to fix that.