dimanche 25 décembre 2016

How to prevent repeated strings (Tickets) in python?

So my goal here is to make the program run so that it continues to draw tickets until it finds one that matches the Winning Ticket. This would work better if there were no repeated tickets but i have no idea as to how i would implement that.

    from __future__ import print_function
    from datetime import date, datetime, timedelta
    from random import randint

    count = 0

    class Ticket:
    #Powerball Lottery Ticket Class'

         def __init__(Ticket, ball1, ball2, ball3, ball4, ball5, pb):
              Ticket.ball1 = ball1
              Ticket.ball2 = ball2
              Ticket.ball3 = ball3
              Ticket.ball4 = ball4
              Ticket.ball5 = ball5
              Ticket.pb = pb

         def displayTicket(Ticket):
              print ("Ticket: ", Ticket.ball1, Ticket.ball2, Ticket.ball3, Ticket.ball4, Ticket.ball5, Ticket.pb)

    WinningTicket = Ticket(randint(0, 69), randint(0, 69), randint(0, 69), randint(0, 69), randint(0, 69), randint(0, 26))
    DrawnTicket = Ticket(randint(0, 60), randint(0, 60), randint(0, 60), randint(0, 60), randint(0, 60), randint(0, 26))

    #Winning Ticket
    print("Powerball Ticket")
    WinningTicket.displayTicket()
    print("----------------")

    #Draws a random ticket
    def randomTicket():
         DrawnTicket = Ticket(randint(0, 69), randint(0, 69), randint(0, 69), randint(0, 69), randint(0, 69), randint(0, 27))
         DrawnTicket.displayTicket()
         return Ticket

    #Draw Random Ticket Until DrawnTicket is = RandomTicket
         while WinningTicket != DrawnTicket:
         randomTicket()
         count += 1
         if WinningTicket == DrawnTicket:
              break

    #Number of DrawnTickets
    print("Number of Drawn Ticket: ", count)




Aucun commentaire:

Enregistrer un commentaire