Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:26:01+00:00 2026-06-14T10:26:01+00:00

So I build a tiny bingo program for my wife to use at her

  • 0

So I build a tiny bingo program for my wife to use at her candle parties. The boards are already generated. This is just a program to call out the numbers.

import random
a = []
a = list(range(1,76))
random.shuffle(a)

def pop(x):
    while 1:
        b = a.pop(0)
        if b <= 15:
            print 'b', b,
        elif b > 15 and b <=30:
            print 'i', b,
        elif b > 30 and b <=45:
            print 'n', b,
        elif b > 45 and b <=60:
            print 'g', b,
        else:
            print 'o', b,
        raw_input('')

pop(1)

Now her parties are getting larger and she is worried about someone cheating so I would like to add in a feature where I could type in the numbers that supposedly won and have the program let me know if those numbers where indeed called. I have tried running it to a file with

def pop(x):
    while 1:
        b = a.pop(0)
        with open('bingo.txt', 'w') as file1:
            file1.write(b,'\n')
        if b ...

but it just opens and then closes back down. No errors or any text to the file. It doesn’t need to go to a file. I just thought that if it did, I could then add in a searchfile feature at the end and know whether the number was called or not.
What would be the best way to find out if the numbers on the “winning” line were actually called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:26:03+00:00Added an answer on June 14, 2026 at 10:26 am

    I would accumulate the numbers called in a set which would get returned from pop. then I’d add a function to read in the “winning” numbers (into a set) and check if that new set is a subset of the numbers which were called:

    import random
    import ast
    
    def pop(a,accumulated=None):
        print "type q to move on to verification"
        if accumulated is None:
            accumulated = set()
        v = 'I can put any string here, as long as it is not "q" :-)'
        while v.lower() != 'q':
            b = a.pop(0)
            if b <= 15:
                print 'b', b,
            elif b > 15 and b <=30:
                print 'i', b,
            elif b > 30 and b <=45:
                print 'n', b,
            elif b > 45 and b <=60:
                print 'g', b,
            else:
                print 'o', b,
            accumulated.add(b)
            v = raw_input('')
        return accumulated
    
    def verify(numbers):
        new_nums = raw_input("enter numbers separated by ',': ")
        nums = ast.literal_eval(new_nums)
        assert( len(nums) == 5 ) #Need 5 numbers to win
        result = set(nums).issubset(numbers)
        print "Verified? ",result
        return result
        #alternatively, and probably slightly more efficient
        # print numbers.issuperset(nums)
        #I prefer the other though as `subset` is easier for me to remember
    
    
    def robust_verify(numbers):
       """
       keep trying to verify the numbers until we succeed
       """
       try:
           verify(numbers)
       except (AssertionError,SyntaxError,TypeError):  #other error conditions might go here too, but these are the ones I can think of right now ...
           robust_verify(numbers)
    
    
    def play_bingo(game_vals=None,accumulated=None):
        if game_vals is None:
            game_vals = list(range(1,76))  #list strictly not necessary here, but why not?
            random.shuffle(game_vals)
    
        nums = pop(game_vals,accumulated=accumulated)
        if not robust_verify(nums):
            play_bingo(game_vals=game_vals,accumulated=nums)
    
    
    play_bingo()
    

    This is made a little more robust by making sure that verify succeeds (e.g. that your user doesn’t accidentally enter a number as 15a,17,22,...)

    As a side note, your attempt at using a file failed because you were opening a file, writing a number to it and closing it each time you “draw” a new number. Since you’re opening the file as 'w' any file that is already there gets clobbered — and so you can only ever store the last number drawn by that method. You’d want to move your while loop into the with statement in order to get that method to work properly (or open the file for appending ('a'), but repeatedly opening a file for appending is typically not a good solution).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making this tiny utility program (Windows Forms) and it would need to save
I build my project with Gradle 1.0 and I use the EMMA plugin for
i'm attempting to build a tiny (or perhaps not so tiny) formula that will
I'm trying to build a tiny skeleton framework for a friend, where each time
We use PDFSharp (the GDI+ build) in one of our web applications. In one
I'm just starting with BDD and I'm trying to build a small app, so
I know this has been asked but I'm still confounded. I'm trying to build
A have a project build with GNU autotools. Now I have a tiny change
I built a tiny menu to use in a bash terminal with multiple options
This is my problem, I have a tiny PHP MVC framework i built. Now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.