Python Projects

Random 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

RANDOM(MODULE)

We will use random’s module function – randrange to generate random number between 1 to 100.

python-py

CONDITIONALS - IF ELIF ELSE

We will use If-Elif-Else to communicate the user for either Higher/Upper Number or for Correct guess.

WHAT TO DO ?

Generate any number between 1 to 100 and keep asking user to guess it till guess is made correct.

HOW TO DO ?

Following are the steps to do :

01.

IMPORT & ASSIGN RANDOM NUMBER

At First, We have to import the random module and assign random number to a variable using randrange function.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>name = input("Write your name ? ")
email = input("Write your email ? ")
mobile = input("Write your mobile Number ? ")
address = input("Write your address ? ")
print("Write something about yourself ? ")
about_me = input("")
print("Write your Professional Experience ? ")
professional_experience = input("")
print("Write your Educational Qualifications ? ")
education = input("")
print("What skills do you have ? ")
skills = input("")
father = input("Write your Father's Name ? ")
marital_status = input("State your Marital Status ")
hometown = input("Where is your hometown ? ")
</pre>
</div>
<p>

02.

ASK TO GUESS IN INFINITE LOOP

Finally, We will exit loop on correct guess and also communicating whether guess is higher or lower.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>print() # Creating Gap with blank line.
print() # Creating Gap with blank line.
print("# Now Printing/Outputing the C.V")
print()
print("Name: " + name)
print("Email-id: " + email)
print("Mobile Number: " + mobile)
print("Address : " + address)
print()
print("About Me: ")
print(about_me)
print("Professional Experience: ")
print(professional_experience)
print("Educational Qualifications: ")
print(education)
print("Skills: ")
print(skills)
print()
print()
print("Personal Information")
print("Father's Name: " + father)
print("Marital Status: " + marital_status)
print("Hometown: " + hometown)</pre>
</div>
<p>
Things We Covered
  • Accepting User Data (Input Function)
  • Generating Random Number (Random Module)
  • Creating IF-ELIF-ELSE (Conditionals)
  • Conditional Event Loop(Infinite Loop with Break)
  • Print/Output the Final Result (Print Function)

Posted by Akshay Gupta

Leave a Reply

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