mercredi 7 avril 2021

Python creating a list that matches with random generated list

I'm trying to create a program where a user inputs numbers between 1 and 9 and the numbers are stored in a list and the program generates 4 numbers between 1 and 10 and then a it states which numbers match. enter image description here

Can anyone help me with my code?

import random
def main():
   print("You are asked to pick 4 unique numbers in the range of 1 to 10.")
       number,list = user_input()
      randomlist = random_gen()

def user_input():
    for i in range(4):
        while True:
          number = float(input("Enter a number: ")
             if number < 1 : or number > 10
                print("Must be in the range of 1 to 10")
                else:
                     break
        list. Append(number)

def random_gen():
    randomlist = random.sample(range(1,10),5)

    for a in list:
        for b in randomlist:
            if(a==b):
                 match=match=1
                break

print("\n\nNumbers picked:",list)
print("Balls Drawn:",randomlist)
print("Number of matches:",match)



Aucun commentaire:

Enregistrer un commentaire