top of page

Python Program to Guess Number | Realcode4you

realcode4you

Below the code to guess the number:

import random;
GUESS = random.randint(0, 100);
lives = 5;
player = int(input("Enter your guess...\n"));
while (player is not GUESS and lives > 0):
    if (player < GUESS):
        print("Wrong, too low.");
    else:
        print("Wrong, too high.");
    lives -= 1;
    player = int(input("\n"+str(lives+1)+" lives left.\nEnter your guess...\n"))
    if (lives > -1):
        print("Correct!")
    else:
        print("You ran out of lives. The correct answer was " + str(GUESS));

Output:








...

...

Comments


REALCODE4YOU

Realcode4you is the one of the best website where you can get all computer science and mathematics related help, we are offering python project help, java project help, Machine learning project help, and other programming language help i.e., C, C++, Data Structure, PHP, ReactJs, NodeJs, React Native and also providing all databases related help.

​

Hire Us to get Instant help from realcode4you expert with an affordable price.

USEFUL LINKS

Discount

ADDRESS

Noida, Sector 63, India 201301

Follows Us!

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn

OUR CLIENTS BELONGS TO

  • india
  • australia
  • canada
  • hong-kong
  • ireland
  • jordan
  • malaysia
  • new-zealand
  • oman
  • qatar
  • saudi-arabia
  • singapore
  • south-africa
  • uae
  • uk
  • usa

© 2023 IT Services provided by Realcode4you.com

bottom of page