Last active
January 23, 2018 13:25
-
-
Save YannBouyeron/cda8f7270582d70a9ad73d3651c75f9e to your computer and use it in GitHub Desktop.
loto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version pour python >= 3.5 | |
import random | |
#l'utilisateur entre ses 3 numeros | |
n1 = int(input('entrez votre premier numero (entre 0 et 20): ')) | |
n2 = int(input('entrez votre second numero (entre 0 et 20): ')) | |
n3 = int(input('entrez votre troisieme numero (entre 0 et 20): ')) | |
#on tire au sort les 3 bons numeros | |
r = random.choices(range(21),k=3) | |
while r[0] == r[1] or r[0] == r[2] or r[1] == r[2]: | |
r = random.choices(range(21),k=3) | |
#comparaisons | |
z = 0 #cest le nombre de bons numeros trouves | |
for i in r: | |
if i == n1 or i == n2 or i == n3: | |
z = z + 1 | |
#affichage du resultat | |
if z < 3: | |
print ('vous avez perdu') | |
elif z == 3: | |
print ('vous avez gagné') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version pour python <= 3.4 | |
import random | |
#l'utilisateur entre ses 3 numeros | |
n1 = int(input('entrez votre premier numero (entre 0 et 20): ')) | |
n2 = int(input('entrez votre second numero (entre 0 et 20): ')) | |
n3 = int(input('entrez votre troisieme numero (entre 0 et 20): ')) | |
#on tire au sort les 3 bons numeros | |
r1 = random.choice(range(21)) | |
r2 = random.choice(range(21)) | |
r3 = random.choice(range(21)) | |
while r1 == r2 or r1 == r3 or r2 == r3: | |
r1 = random.choice(range(21)) | |
r2 = random.choice(range(21)) | |
r3 = random.choice(range(21)) | |
r = [r1, r2, r3] | |
#comparaisons | |
z = 0 #cest le nombre de bons numeros trouves | |
for i in r: | |
if i == n1 or i == n2 or i == n3: | |
z = z + 1 | |
#affichage du resultat | |
if z < 3: | |
print ('vous avez perdu') | |
elif z == 3: | |
print ('vous avez gagné') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
#l'utilisateur entre ses 3 numeros | |
n = input('entrez vos 3 numeros (entre 0 et 20 séparés par des virgules ou des espaces): ') | |
x = sorted([int(i) for i in n.replace(" ", ",").strip(" ").split(",") if i != '']) | |
#on tire au sort les 3 bons numeros | |
r = sorted(np.random.choice(range(21),3,replace=False)) | |
#comparaison et affichage du resultat | |
if x == list(r): | |
print ('vous avez gagné') | |
else: | |
print ('vous avez perdu') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment