-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessing_game.py
34 lines (24 loc) · 984 Bytes
/
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
#This is a guess the number game.
import random
print("Hello sir, what is your name?")
name = input()
while name.isalpha() == False:
print("A name cannot contain any number! Please type it again:")
name = input()
print("Nice to meet you " + name + ", Now try to guess the number I've been thinking about")
number = random.randint(1,10)
tentatives = 0
while tentatives < 6:
guess = input()
if guess == str(number):
print("Congratulations, you guessed it right, my number was: " + str(number) + " You guessed it in " + str(tentatives+1) + " tries")
exit()
elif tentatives == 5 and guess != str(number):
print("Sorry, you tried too many times, better luck next time!")
exit()
else:
if int(guess) > number:
print("Not the right number, it's too high, Try again!")
elif int(guess) < number:
print("Not the right number, it's too low, Try again!")
tentatives = tentatives + 1