Write Simple Number Guessing Game Python Program Code Generate Two Random Integers 1 10 In Q37022965

Write a simple number guessing game Python program. In thiscode, generate two random integers between 1-10 (both included) andask the user to guess these numbers in five attempts. Printappropriate responses to the user such as “You won!” or “Youfailed”


Solution


Guess: 5 Guess: 3 Guess: 6 You won ! import random generating a random number number-random.randint(1, 10) count-0 while True

import random

# generating a random number

number = random.randint(1, 10)

count = 0

while True:

# taking user input

n = int(input(“Guess: “))

count += 1

if n == number: # number matched

print(“You won!”)

break

if count == 5: # count is over

print(“You failed”)

break

# Hit the

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.