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

8037 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What is the outcome of the following code? print(2*[3,4,5])


Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


How can you take a list of numbers and add 3 to every number in the list using only one line of code?


How would you loop over every key and value in a python dictionary?


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences