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)

Related Python Mentoring answers

All answers ▸

How would you get a piece of code to print the numbers 1 to 10


How might we implement the bubble sort algorithm in Python


What are docstrings and how do I use them to improve my code readability?


How do you define a class in python