Question

In: Computer Science

write a simple python program that takes in 6-50 random numbers the user types in and...

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!

Solutions

Expert Solution

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!


Related Solutions

Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Write a Python program that takes as input two numbers, the height, and width of a...
Write a Python program that takes as input two numbers, the height, and width of a rectangle. It then prints a rectangle with height lines and width characters in each line. The rectangle should contain information regarding its dimensions and area inside (centered vertically but not horizontally). If any part of the information (including two stars on each end and a space before and after the line) does not fit in the rectangle, then print the complete information after the...
Using Python, write a simple application that takes user input of plaintext and key, and encrypt...
Using Python, write a simple application that takes user input of plaintext and key, and encrypt the plaintext with Vigenere Cipher. The application should then print out the plaintext and the ciphertext.
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
Write a python program that asks the user to enter a string containing numbers separated by...
Write a python program that asks the user to enter a string containing numbers separated by commas, e.g., s = '1.23,2.4,3.123', Your program should then calculate and print the sum of the numbers entered. Hint: you need to iterate over the string searching for the commas, i.e. their index. The first number is obtained by slicing between the start of the string and the index of the first comma. The second number is between the last comma and the next...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
(+30) Write a python program that generates four random between -50 and +50 using python’s random...
(+30) Write a python program that generates four random between -50 and +50 using python’s random number generator (RNG) see the following code (modify as needed ) import random a = 10 # FIX b =100 # FIX x = random.randint(a,b) # (1) returns an integer a <= x <= b # modify a and b according to the lab requirement print('random integer == ', x) and displays 1. the four integers 2. The maximum integer 3. The minimum integer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT