write a program using random function to guess the number and then print true or false if the answer is correct or wrong if the answer is incorrect respectively.

import random
a=random.randrange(1,10)
b=int(input("enter the  which pc is thinking "))
if a==b:
    print("omg! you are correct")
    print("i also thinked",a,"what a coincidence")
else:
    print("sorry you are wrong")
    print("i have",a,"write now better luck next time")
OUTPUT-
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\Wap to to form a game.py
enter the no. which pc is thinking 4
sorry you are wrong
i have 9 write now better luck next time
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\Wap to to form a game.py
enter the no. which pc is thinking 5
sorry you are wrong
i have 8 write now better luck next time
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\Wap to to form a game.py
enter the no. which pc is thinking 5
sorry you are wrong
i have 2 write now better luck next time
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\Wap to to form a game.py
enter the no. which pc is thinking 5
omg! you are correct
i also thinked 5 what a coincidence
>>> 

Leave a Reply

Back To Top