mercredi 18 août 2021

Created a python lottery draw using if elif else statements + import random choice

I have tried to create a lottery game in python by using import random choice and if, elif and else statements. I guess it is working as it should. How can I use a function to replicate this lottery game? Thanks

from random import choice  # import module

# I created a list of lottery numbers below:
lottery_numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'a', 'b', 'c', 'd', 'e']
#  the person who gets this combinations of numbers and letters on the ticket wins
print("if the following numbers or letters are chosen \n"
      "the person  wins a prize: e, 1, b, 10 ")

if (choice(lottery_numbers)) == 'e':
    print("winner!!")
elif (choice(lottery_numbers)) == '1':
    print('winner!')
elif (choice(lottery_numbers)) == 'b':
    print("winner")
elif (choice(lottery_numbers)) == '10':
    print("winner")
else:

    print('you lose, next time!!')

Aucun commentaire:

Enregistrer un commentaire