Number Guessing Game in Python
Today I got to build a variety of games in python treatment python libraries. This an easy range game wherever the pc machine generates a random range within the given variable as per program needed examples -- one to one hundred is given input and therefore the user should guess the quantity in five attempts.
Based on the pc user can some hints to the user the range of the amount the quantity just like the number is high or low. Then you print you lose the sport or win the sport
Let's begin with step by step
To generate variety in python I take advantage of the python library and therefore the library name is random and import it.
import random
I use the random range between one to one hundred and store it in an exceedingly variable name as num
num = random.randint(1,100)
Now I take the user name as within the kind of input and store it to be a variable name because the name
name = input("what is your name")
I produce a variable name as guess_number and assign zero to that later we are going to increase this worth on every iteration of the loop
print('hello' + name + 'i am estimation range between one to 100')
while guess_number < 5:
guess = int(input())
guess_number += one
if guess < num:
print('Your guess is just too low')
if guess > num:
print('Your guess is just too high')
if guess == num:
break
I process the management statement of the whereas loop. it's a most of five attempts to guess the quantity.
Below it, we have 3 conditional statements.
In the initial, if statement we tend to face live scrutiny if the guy maybe is a smaller quantity than the generated vary if this statement evaluates to true, we tend to print the corresponding Guess.
Similarly, we tend to face live checking if the guess is larger than the generated vary.
The final if the statement has the break keyword, which may terminate the loop entirely, thus once the guess is up to the generated very loop gets terminated.
Below the whereas loop, we would like to feature another attempt of condition statements,
if guess == num:
print('You guessed the quantity in ' + str(guess_number) + ' tries!')
else:
print('You failed to guess the quantity, the quantity was ' + str(number))
let's run the game and enjoy it
Enter your number -- 55
it is a low number
Enter your number -- 65
It is a high number
Enter Your Number-- 63
It is a high number
Enter your Number -- 59
It is correct
You are win
#snake #c #code #website #programming #coding #java #programmer #webdeveloper #javascript #ballpython #css #html #js #computerscience #coder #php #linux #softwaredeveloper #machinelearning #sass #codinglife #datascience #programmers #softwareengineer #monitor #webdev #ballpythonsofinstagram #bash #django
#snake #c #code #website #programming #coding #java #programmer #webdeveloper #javascript #ballpython #css #html #js #computerscience #coder #php #linux #softwaredeveloper #machinelearning #sass #codinglife #datascience #programmers #softwareengineer #monitor #webdev #ballpythonsofinstagram #bash #dj#website #programming #coding #code #snake #c #javascript #webdeveloper #programmer #java #computerscience #html #css #coder# softwaredeveloper# machinelearning #datascience #codinglife #linux #ballpython #pythonprogramming #php #programmers #softwareengineer #programmingmemes
python programming
python tutorial
python interview questions
python online compiler
python compiler
पाइथन
python language
#snake #c #code #website #programming #coding #java #programmer #webdeveloper #javascript #ballpython #css #html #js #computerscience #coder #php #linux #softwaredeveloper #machinelearning #sass #codinglife #datascience #programmers #softwareengineer #monitor #webdev #ballpythonsofinstagram #bash #dj#website #programming #coding #code #snake #c #javascript #webdeveloper #programmer #java #computerscience #html #css #coder# softwaredeveloper# machinelearning #datascience #codinglife #linux #ballpython #pythonprogramming #php #programmers #softwareengineer #programmingmemes
#somaymangla #somaymangla #somaymangla #somaymangla #somaymangla #somaymangla
Author
#snake #c #code #website #programming #coding #java #programmer #webdeveloper #javascript #ballpython #css #html #js #computerscience #coder #php #linux #softwaredeveloper #machinelearning #sass #codinglife #datascience #programmers #softwareengineer #monitor #webdev #ballpythons
No comments:
Post a Comment