[Python] Using random.randint help in python

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    The following code is my attempt at simulating a lottery.

    import random

    def lottery(numbers):
    lottoNumbers = [randint('0,100') for count in range(3)]

    if numbers == lottoNumbers:
    print('YOU WIN $10,000')
    else:
    print('YOU LOSE,DUN DUN DUNNN!')
    return numbers


    def main():
    numbers = int(input('Enter a number: '))
    if numbers == lottoNumbers:
    numbers = lottery(numbers)
    else:
    numbers = lottery(numbers)




    main()


    Hey guys I've gotten this far with the help you've given me. I'm trying to write the code so that 3 lotto numbers at random will be chosen. Then the user must enter 3 of his/her own lotto numbers. If they get all 3 correct then they win the whole prize, if they get the 3 numbers but not in the correct order they win some of the prize. Obviously if they guess all wrong then a print statement would state that. What I'm confused about is how can I write the code so that the user can enter 3 numbers to try matching the random lottery numbers. I also want to print the 3 lottery numbers after the user inputs his/her choices. Any ideas guys?

    Thanks for your help everyone.

    Continue reading...

Compartilhe esta Página