forked from kishanrajput23/Awesome-Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guess the number.py
103 lines (42 loc) · 1.5 KB
/
Guess the number.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Author : Vishwajeet Bamane
#Last modified Date:10/05/2020
# Number Guessing Game
# using Python
#importing random module to generate random number of chances
import random
print("Number guessing game")
#generating random rumber using randint() between 0 and 9
number = random.randint(0,9)
chances = 0
print("Guess a number (between 1 and 9 ):")
# While loop to count the number
# of chances
while chances < 5:
# Enter a number between 1 to 9
guess = int(input())
# Compare the user entered number
# with the number to be guessed
if guess == number:
# if number entered by user
# is same as the generated
# number by randint function then
# break from loop using loop
# control statement "break"
print("Congratulation YOU WON!!!")
break
# Check if the user entered
# number is smaller than
# the generated number
elif guess < number:
print("Your guess was too low: Guess a number higher than", guess)
# The user entered number is
# greater than the generated
# number
else:
print("Your guess was too high: Guess a number lower than", guess)
# Increase the value of chance by 1
chances +=1
# Check whether the user
# guessed the correct number
if chances >=5:
print("YOU LOSE!!! The number is", number)