Make a game where the computer will guess a random number for different given ranges eg 1-10, 10-20, 30-20. You are given only 5 lives double digits are allowed like 11. the program must return not a number in the given range if you input anything that isnt in the given range for example 1-10; 1,2,3,4,5,6,7,8,9,10. The program should also ask you if u want to play again
import random
answer="y"
while answer.lower()=="y":
lives=5
minNumber=int(input("Enter min number: "))
maxNumber=minNumber
while maxNumber<=minNumber:
maxNumber=int(input("Enter max number: "))
secretNumber=random.randint(minNumber, maxNumber)
print(f"Compute, try to guess the number between {minNumber} and {maxNumber}.")
while lives>0:
computerGuess=random.randint(minNumber, maxNumber)
print(f"Computer: I think the secret number is {computerGuess}.")
if computerGuess==secretNumber:
print("Correct answer. You won the game.")
break
else:
print("Wrong answer.")
lives-=1;
if lives<=0:
print("You lose the game.")
answer=" "
while answer.lower()!="y" and answer.lower()!="n":
answer=input("Do you want to play again? y/n: ")
Comments
Leave a comment