samedi 4 septembre 2021

in how many times i guess the right number? [closed]

i have created a program that guess the randomly generated number in just 5 attempts. please guide me how can i write code for:

  • in which attempts i guess the number
  • How many times i played the game
  • And how many time i lose or win the game.

import random
print("Welcome to this game")
name = input("Enter your name: ")


def game():
    random_number = randint(0, 10)
    print("Guess the number b/w 0-10 in 5 attempts")
    i = 0
    r = 0
    while i < 6:
        user_number = int(input("input your number: "))
        if user_number == random_number:
            print("Congratulations you have guessed the number")
            r = 1
        else:
            print("Try again,")
            i = i+1

    if r == 0:
        print("Sorry you lose it ")
        print("My number was ",end='')
        print(random_number)


def main():
    game()
    while True:
        another_game = print("Do you want to play another game (y/n)?")
        if another_game == 'y':
            game()
        else:
            break


main()
print("thanks for playing this game")




Aucun commentaire:

Enregistrer un commentaire