In: Computer Science
write a simple python program that takes in 6-50 random numbers the user types in and then guesses the next 6 of numbers that will be produced based on the numbers entered. it's something like a lottery program. You can use any algorithm you want but it has to be in the python programming language.
Thank you!
Ans:
'''
The required program taking the previously entered random set of numbers by a user guesses the next six numbers that the user might enter
'''

import random
# for guessing I have used the same old binary search to predict a
next number
def computer_guess(num,l,h):
low = l
high = h
guess = (low+high)//2
while guess != num:
guess = (low+high)//2
print("The computer is thinking maybe you'll enter", guess,"next!
or maybe")
if guess > num:
high = guess
elif guess < num:
low = guess + 1
print("\n After a lot of thinking...")
print("The next number you'll enter maybe : ", guess, ", I hope I
am correct!")
print("\n")
def main():
n = int(input("Enter the total number of numbers that you want to
enter : "))
print("Enter "+str(n)+" numbers :")
lst = []
for _ in range(n):
num = int(input("Enter a number: "))
lst.append(num)
print("\nI Think the next 6 numbers that you'll enter are :
")
for i in range(6): # takes random six numbers from the previously
entered list to predict the next 6 numbers
computer_guess(random.choice(lst),min(lst),max(lst))
if __name__ == '__main__':
main()
# This program gave the following output on sample run -

# and it goes on until next six numbers are guessed by the program!
# PLEASE DO LIKE AND UPVOTE IF THIS WAS HELPFUL!
# THANK YOU SO MUCH IN ADVANCE!