Program to Guess the Number || Python
In this we are going to see a basic program of number guessing game in Python Programming Language.



from random import randint


def main():
    n = randint(1, 6)
    ans = False
    chances = 0
    print("Note: Guess the number in 4 chances, 1 point will be deducted for each incorrect guess.")
    while ans == False and chances < 4:
        n2 = int(input("Guess the number: "))
        if n == n2:
            ans = True
            print("Correct guess. Points awarded: ", 4-chances)
        else:
            print("Incorrect guess.")
            chances += 1
        if chances == 3:
            print("Last chance.")
        elif chances == 4 and ans == False:
            print("You've run out of chances. 0 points awarded.")


main()

# Coded by Shreya Idate


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post