-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber Game
84 lines (69 loc) · 2.72 KB
/
Number Game
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /anaconda/bin/python3.6
# Number Guessing Game
# go onto https://repl.it/languages/python3 to use
# input using just numbers pls ^_^
import random
from time import sleep
import numpy as np
list_guess = [] # just defining inital variables and creating empty lists
list_difference = []
list_winner = []
number = random.randint(0,10)
player_number = 1
def checker(guess, player_number): # checks to ensure guesses meet the game's protocol
while (guess > 10 or guess < 0):
print("Sorry Player {}, you must make a guess between 0 and 10".format(player_number))
sleep(1)
print("Inclusive ;)")
sleep(1)
guess = int(input("Please make another guess"))
while (guess in list_guess):
print("Sorry Player {}, that guess has already been made".format(player_number))
sleep(1)
guess = int(input("Please make another guess"))
if (guess > 10 or guess < 0):
checker(guess, player_number)
else:
list_guess.append(guess)
print("Hello, welcome to the Number Guessing Game.")
sleep(1.5)
print("In this game, you have to guess a number between 0 and 10")
sleep(1.5)
print("Inclusive ;)")
sleep(1)
print("Pay attention though, the person who is the FURTHEST away will win!")
sleep(1)
num_of_player = int(input("How many of you will be playing today?"))
sleep(1)
print("Ok, lets play!")
sleep(1)
while num_of_player > 0: # loops through number of players to ensure every player get to guess
guess = int(input("Ready Player {}, make your guess".format(player_number)))
checker(guess, player_number)
num_of_player = num_of_player - 1
player_number = player_number + 1
for guess in list_guess: # determines how far away the guesses are
difference = abs(number - int(guess))
list_difference.append(difference)
print("Well players, the number was {}".format(number))
sleep(1)
for i in list_guess: # prints all players guesses and their guess difference
player_number = (list_guess.index(i) + 1)
print("Player {}, you guessed {}... and are {} digits away".format(player_number, i, list_difference[list_guess.index(i)]))
player_number = player_number + 1
sleep(1)
winner = max(list_difference) # finds the best guess and accounts for ties.
for win in list_difference:
if win == winner:
list_winner.append(list_difference.index(win) + 1)
list_difference[list_difference.index(win)] = 0
print("That means... the winner is...")
sleep(1)
if len(list_winner) == 1:
print("Player {}".format(list_winner[0]))
else:
print("Or should I say winners...")
sleep(1)
print("In a remarkable turn of events, we have a tie!")
sleep(1)
print("Player {} and Player {}, you are the winners!".format(list_winner[0], list_winner[1]))