Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10

The python code for this is below:

from random import randint

goal = randint(1,10) tries = 3

while tries > 0:     guess = int(input("Please guess the number:"))     if guess == goal:         print("Congratulations you won!")         break     else:         tries-=1         print("Incorrect! %d tries left!"%tries)

Answered by Python tutor

9150 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Which function is ran when an object is instantiated?


Write a Python script to take a product name as input and then automatically google search reviews for it and open the top 3 search results in different tabs


Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.


How do I check if a number is prime using a python program?


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning