-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_6.py
35 lines (34 loc) · 1.26 KB
/
project_6.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
# guessing number game .
# for easy level 10 attempts and for hard 5 attempts.
import random
randomNum = random.randint(1,100)
print(randomNum)
print("------------Number Guessing Game----------------")
def compare(attemptNo,n) :
flag = 0 # all incorrect guess , loose the game
print(f"You have {attemptNo} attempts.")
for i in range(0,attemptNo,1) :
if n == randomNum :
print(f"You won, The random number generated was {randomNum}")
flag = 1 # won the game.
break
elif n > randomNum :
print(f"You have {attemptNo-i} attempts left.")
print("Your number is high , Guess Low ")
n = int(input("Enter a number : "))
else :
print(f"You have {attemptNo-i} attempts left.")
print("Your number is low , guess high")
n = int(input("Enter a number : "))
if flag == 0 :
print(f"You attempts are over ,Random number was {randomNum} You have lost the game .")
def main() :
choice = input("Enter the level 'Easy' or 'Hard'")
n = int(input("Guess A number between 1 to 100 including both."))
if choice == "Easy" :
attemptNo = 10
compare(attemptNo,n)
else :
attemptNo = 5
compare(attemptNo,n)
main()