Hello!
I’m trying to create a word bingo generator workflow for my class. I can fill a txt with words and the scripts automatically pulls out the words and creates bingo cards out of it.
Now I’m looking for a good way to print those cards for my students. First I tried to output a ASCII table txt because I love keeping things simple but it didn’t work at all.
Now I’m creating a csv, open it with Numbers, edit the title row and column, press print, edit it again till it is in a printable form, print it out and cut it with my scissors. This is somehow ok, but it feels unnecessary complicated.
Can anyone think of a better way to export the cards into a readable standard format without using so much apps?
This is my script:
import random
import csv
import os
def read_words_from_file(file_path):
with open(file_path, 'r') as file:
words = [line.strip() for line in file]
return words
def generate_bingo_cards(words, size, num_cards):
cards = []
for _ in range(num_cards):
card = random.sample(words, size)
cards.append(card)
return cards
def write_bingo_cards_to_csv(cards, size, input_file):
base_name = os.path.basename(input_file)
output_file = os.path.splitext(base_name)[0] + "_bingo.csv"
with open(output_file, 'w', newline='') as file:
writer = csv.writer(file)
for card in cards:
rows = [card[i:i+5] for i in range(0, size, 5)]
writer.writerows(rows)
writer.writerow([]) # Add an empty row for visual separation
def main():
file_path = input("Enter the path to the text file: ")
words = read_words_from_file(file_path)
size = 25 # Size of each bingo card (5x5)
num_cards = 11 # Number of cards to generate
if len(words) < size:
print("Error: Insufficient number of words in the file.")
return
cards = generate_bingo_cards(words, size, num_cards)
write_bingo_cards_to_csv(cards, size, file_path)
print(f"Bingo cards have been generated and saved to '{os.path.splitext(file_path)[0]}_bingo.csv'.")
if __name__ == "__main__":
main()