Python Projects

Number Guessing Game with Python

PREREQUISITES

To Practice this Program, you should have a basic knowledge of the following Topics:

PYTHON-FUNCTIONSS

INPUT & PRINT FUNCTION

We will use Input & Print Function to collect & print data from the website user into variables.

dt

INTEGER & FLOAT

We will accept the user input in float or integer so that it can be calculated.

python-py

COMPARISON OPERATORS

We will use Comparison Operators to compare the user given number with lottery number.

python-py

CONDITIONALS - IF ELIF ELSE

We will use If-Elif-Else to print out the result as per condition.

WHAT TO DO ?

Given, lottery_number = 22.
Ask a user to guess the lottery number between 1 to 100.

HOW TO DO ?

Following are the steps to do :

01.

ASK NUMBER

At First, We will ask a number from user to guess.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>lottery_number = 22

number = int(input("Guess a winning lottery number between 1 to 100 . "))
</pre>
</div>
02.

CREATE CONDITIONS

Finally, We will create conditionals to print out the result as per conditions.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>if number>22:
  print("higher")

elif number<22:
  print("lower")

else:
  print("You made a correct guess.")</pre>
</div>
Things We Covered
  • Accepting User Data (Input Function)
  • Creating IF-ELIF-ELSE (Conditionals)
  • Print/Output the Data (Print Function)

Posted by Akshay Gupta

Leave a Reply

Your email address will not be published. Required fields are marked *