Recabamos por el mundo online y así tenerte la respuesta a tu dilema, si tienes alguna inquietud déjanos la pregunta y responderemos porque estamos para servirte.
Ejemplo: oportunidad de lotería de Python
import random
correct =0
total =0
run =1
howmany =int(input("How many correct guesses should there be? (0-6) "))if howmany <0:print("That was below 0.")
quit()elif howmany >6:print("That was over 6.")
quit()
runs =int(input("How many runs should there be? "))if runs <1:print("There has to be at least one run.")
quit()while run <= runs:
correct =0
howoften =0while correct != howmany:
correct =0
guess =[]
drawing =[]whilelen(guess)<6:iflen(guess)<6:
number = random.randint(1,50)ifnot number in guess:
guess.append(number)whilelen(drawing)<6:iflen(drawing)<6:
number2 = random.randint(1,50)ifnot number2 in drawing:
drawing.append(number2)
x =0
y =0while y <len(guess):while x <len(guess):if guess[x]== drawing[y]:
correct +=1
x +=1
y +=1
x =0
howoften +=1print("run",(run),"| draw ",
howoften,"| correct", correct)
total += howoften
run +=1
average =round((total / runs),2)print("To get", howmany,"correct guesses", runs,"times, there had to be a total of", total,"tries. That's an average of ", average,"tries per run. (so the chance is 1:"+str(average)+")")input("Hit Enter to exit")
Sección de Reseñas y Valoraciones
Si guardas alguna incertidumbre y disposición de mejorar nuestro reseña eres capaz de ejecutar una nota y con mucho gusto lo analizaremos.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)