Answer to Question #204661 in Python for LEROY

Question #204661

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


1
Expert's answer
2021-06-08T12:12:27-0400
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: ")  






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS