TASK-
Write a python Program for guessing a number with following conditions
- There should be limited number of tries.
- There should be a message printed as game over when all tries fail.
- If the number is guessed before end of tries a suitable message should be printed.
- After each try must show number of tries left.
- At last show the number of tries used if number is guessed before end of tries.
CODE:
n=18 #fixed number
c=9 #limited tries (condition 1)
while (c>0): #to fix the tries
u=int(input("Enter the number: "))
if (u>n):
print("Entered number is greater!!")
c=c-1 #condition 4
print("You are left with",c,"tries")
elif(u<n):
print("Entered number is smaller!!")
c=c-1
print("You are left with",c,"tries")
else:
c=c-1
print("You guessed correctly")#condition 3
break
if (c==0):
print("Game over") #condition 2
else:
print("You guessed correct number in",9-c,"tries") #condition 5