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 8365295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:37:34+00:00 2026-06-09T12:37:34+00:00

I have a simple script to generate UK lottery numbers (7 numbers, 1 to

  • 0

I have a simple script to generate UK lottery numbers (7 numbers, 1 to 49 inclusive).
My code has a function that generates 7 random numbers into a list, runs set on the list removing duplicate numbers, checks if there are still 7 members in the list, and if not the function calls itself to generate 7 new numbers.

However, when the function calls itself it does not return the list.

I’d appreciate knowing what I’m doing wrong here.

from random import randint

def lotto():

    l = []
    for r in range(1,8):
        l.append(randint(1,49))

    print "DEBUG: l=", l
    print "DEBUG: set(l)=", set(l), len(set(l))

    if(len(set(l)) !=7):
        lotto()
    else:
        print "Before return l, l = ", l
        return l

def main():
    numbers = lotto()
    print numbers

Here is a sample run that does not work correctly:

DEBUG: l= [44, 32, 12, 12, 33, 16, 31]
DEBUG: set(l)= set([32, 33, 44, 12, 16, 31]) 6
DEBUG: l= [46, 20, 10, 24, 16, 35, 44]
DEBUG: set(l)= set([35, 10, 44, 46, 16, 20, 24]) 7
Before return l, l =  [46, 20, 10, 24, 16, 35, 44]
None

And a sample run that does work correctly:

DEBUG: l= [20, 5, 21, 37, 10, 44, 38]
DEBUG: set(l)= set([37, 38, 10, 44, 20, 21, 5]) 7
Before return l, l =  [20, 5, 21, 37, 10, 44, 38]
[20, 5, 21, 37, 10, 44, 38]
  • 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-09T12:37:35+00:00Added an answer on June 9, 2026 at 12:37 pm

    You’re not returning the result of the recursive call.

    if(len(set(l)) !=7):
        return lotto()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple script of code that reads a PHP file and when
Does anyone have a simple shell script or c program to generate random files
I have a simple CGI script that would generate plain text content on demand.
I have a simple script to check how many files a user has uploaded:
I have this simple script that I'm working on. I must admit, I'm totally
I have a simple script that does some search and replace. This is basically
I have a simple script that pulls about 100 million results, 1 million at
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have tried to use the php script to generate PDF with a simple
I have been using this simple script to generate images from text: <?php header('Content-type:

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.