Skip to content

Instantly share code, notes, and snippets.

@skatesham
Last active December 27, 2023 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skatesham/4cddd30db2f6b7f9e02bd3b97884ac5d to your computer and use it in GitHub Desktop.
Save skatesham/4cddd30db2f6b7f9e02bd3b97884ac5d to your computer and use it in GitHub Desktop.
Mega sena script - 6 numbers game paid R$ 4,50 - Best run teh script then start playing
from random import randint
import re
def generate(size):
unique_numbers = list()
while(len(unique_numbers) < size):
new_value = randint(1, 60)
if (new_value not in unique_numbers):
unique_numbers.append(new_value)
unique_numbers.sort()
return unique_numbers
def play(played_game):
tentate = 0
match = False
while (not match):
random_chance = generate(6)
tentate += 1
if(random_chance == played_game):
match = True
print("Sucesso você ganhou!")
return tentate
def init(size=6):
played_game = generate(6)
print("Seu jogo:")
print(played_game)
return played_game
def show(tentate):
value = int(tentate * 4.5)
formated_tentate = to_dot_number(tentate)
print("Quantidade de tentativas " + formated_tentate)
print(f'Valor gasto R$ {to_dot_number(value)},00')
def to_dot_number(value):
return re.sub(r'(?<!^)(?=(\d{3})+$)', r'.', str(value))
def run():
size = 6
played_game = init(size)
tentate = play(played_game)
show(tentate)
if __name__ == "__main__":
run()
@skatesham
Copy link
Author

Usage

python3 sena.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment