Last active
July 30, 2018 15:00
-
-
Save tliesnham/fea9316bebce8c23bba1eb29e9778ada to your computer and use it in GitHub Desktop.
A Python based guess the number game where the computer attempts to guess the user's number based on past input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
rounds = 0 | |
guesses = 0 | |
numbers = [] | |
print("Welcome to Guess! Each round a player picks a number between 1 and 10. The computer then attempts to guess this number.\n") | |
def success_rate(): | |
if guesses > 0: | |
return (guesses / (rounds-10)) * 100 | |
return 0 | |
while True: | |
players_number = int(input("Enter a number between 1 and 10: ")) | |
numbers.append(players_number) | |
rounds += 1 | |
if rounds > 10: | |
random.shuffle(numbers) | |
guess = numbers[len(numbers)-1] | |
print("Computer guesses: {}\n".format(guess)) | |
if guess == players_number: | |
guesses += 1 | |
print("Success rate: {}%".format(success_rate())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the user inputting random numbers this would return a theoretical win rate of 10%. Anything over 10% would suggest that the numbers are not random.