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 ▸

With the help of Pandas and Numpy library create a DataFrame with the columns "Name", "Surname", "Age" and "Gender", create as many rows as you want. Print out the result.


[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


Manually implement a function that finds the smallest value in a list of integers and print it.


How do I define a function in Python?


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