science facts and news

Thursday, July 22, 2021

Python guessing the number!

 import math

import random

correct_number = random.randint(120)
print(correct_number)
guess_counter = 0
guess_limit = 3
user_guess = 0

while guess_counter < guess_limit and correct_number != user_guess:
    user_guess = int(input('Enter a number (1-20): '))
    guess_counter += 1
    if user_guess == correct_number:
        print("Great! That's correct")
    elif user_guess < correct_number:
        print('less! increase the value')
    elif user_guess > correct_number:
        print('High! decrease the value')

    else:
        print('Sorry! out of guesses!')

No comments:

Post a Comment

About Me

Kohalpur, Banke, Nepal
Hi, I'm Roshan , a student just trying to explore the world of programming