# Python Project beginner - Number guessing game.

 python project-Number guessing

Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Â
Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â

In this python project beginner we must use random module. Random module has many function you can read by python docsÂ to read random module. In this module we must use random.randint(starting number , ending number).

``````import random
rnumber = random.randint(1,200)

guessnumber = None
gues = 0

while guessnumber!=rnumber:
guessnumber = int(input("Enter your guess number "))
gues += 1
if gues == 15:
print("your chance is finish you have only five chance to guess number")
break

if guessnumber==rnumber:
else:
if guessnumber>rnumber:
print("choose a lower number")
else:
print("choose a highest number")

print(f"your guess number is {gues} ")

with open("highscore.txt","r")as f:

if highpoint>gues:
print("you have broken highscore")

with open("highscore.txt","w")as f:
f.write(str(gues))``````

How to write this program. At the first we import the random module.
pip install random
Use random.randint fuction. It is generate automatically int number. Print int number any you give range.
In tis program we give 1,200 so it automatically print any number up to 1 to 200 We define the
guessnumber is none and gues is 0.Use while loop upto guessnumber not equasl to 0.
Input any number from user ang guess is incriment with +1.Use input and program condition is check.
User have 15 chance to guess the prom because guess isincriment every input by user.
if userinput is match any condition then check highscore.txt file.
To compaire to new highscore to old user new user.New user is get highscore
than open file highscore.txtand write new user highscore point.

F string vs Format

``````name = "samir"
talent = "ethical"
whois = "he is a {0} and he is a master in {2} profession in {1}".format(name,type,talent)
print(whois)``````

Format is use to insert variable in string value. Format is use in old days. Now use f string. Format is difficult to read and write is hard. Old program sources code there is almost use a format so., format is very important to know. If you don't know this format keyword. It is difficult to your program journey. Also difficult to read old program.Â

Now days f string is famous but some programmer is use format now. Mostly Hacker is mostÂ  use format. Because some of programming class doesn't teach about format.