-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_guessing_game.py
51 lines (38 loc) · 1.12 KB
/
number_guessing_game.py
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
# Starting Out with Python (4th Edition).
# Tony Gaddis.
# Page 305.
# Q. 20 Number Guessing Game.
from random import *
from matplotlib.pyplot import *
MIN = 1
MAX = 100
m = 1
x_values = []
print("--- NUMBER GUESSING GAME ---\n")
print("Enter Number Between 1 - 100.")
while m == 1:
x = randint(MIN, MAX)
x0 = int(input("Enter Guess Number: x0 = "))
if x0 >= MIN and x0 <= MAX:
x_values.append(x0)
if x > x0:
print("Too Low Try Again...")
elif x < x0:
print("Too High Try Again...")
else:
print("Congartulations!")
N = len(x_values)
if N <= 3:
print("Great Guess!")
print("Number of Times Guessed: N = ", N)
print("Correct Guess: x = ", x0)
title("Statistics.")
xlabel("Number of Attempts.")
ylabel("Guessed Numbers.")
hist(x_values, bins = N, ec = "black")
show()
print("\n Press 1 To Start Again...")
m = int(input())
else:
print("Error!")
print("Enter Number Between 1 - 100.")