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

8194 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Explain how python programs are structured and give an example of how methods are initiated


Create a program that checks for syntactical errors in an email address.


Ask the user for a number and output the smallest divisor, bigger than one, for the inputted number. Output "Prime" if the number is a prime number.


Write a python function that takes a string as parameter and returns the character in the string with the most occurrences, along with the number of times this character occurs


We're here to help

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

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences