Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Python coding help

    Assignment 1
    6
    Begin a new
    Python
    program
    .
    Create a
    program
    that generates numbers for a lottery ticket. The program should generate 6
    random numbers from 1 to 9. Store these numbers in an array. There should not be duplicates.
    You will do this by searching for each new random numbe
    r in the array. If it is found, have the
    computer find another number.
    You will then print out the numbers in order from lowest to highest. To do this, you will
    create a
    function to perform
    a bubble
    -
    sort.
    Watch and follow along with this video to learn how to
    flowchart the logic of a
    bubble sort:
    https://www.youtube.com/watch?v=Z4Fkv5l1wak
    The program should t
    hen display the output on the screen, and in a file called
    LotteryResults.txt

  2. #2
    New Coder
    Join Date
    Nov 2016
    Location
    South Africa, Cape Town
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    Lol for the video...

    Code:
    import random
    
    theFile = open("LotteryResults.txt", "w")
    
    counter = 0
    numbers = []
    
    while counter <= 5:
        rand = random.randint(0, 49)
        if rand in numbers:
            pass
        else:
            numbers.append(rand)
            counter += 1
    
    print numbers
    map(lambda x : theFile.write(x) , str(numbers))
    
    theFile.close()


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •