python lottery 6 out of 49

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 = 0
    while correct != howmany:
        correct = 0
        guess = []
        drawing = []

        while len(guess) < 6:
            if len(guess) < 6:
                number = random.randint(1, 50)
                if not number in guess:
                    guess.append(number)
        while len(drawing) < 6:
            if len(drawing) < 6:
                number2 = random.randint(1, 50)
                if not number2 in drawing:
                    drawing.append(number2)

        x = 0
        y = 0
        while y < len(guess):
            while x < len(guess):
                if guess[x] == drawing[y]:
                    correct += 1
                x += 1
            y += 1
            x = 0
        howoften += 1
        print("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")

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source