top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Simple App using Python: Number Guessing Game

Writer's picture: arijbentejarijbentej


In this post, I will show you how to create a simple number guessing game using Python. First of all, I will explain the rules of the game that I have created. Then, I will show you the code and at the end I will perform a simple test case.


1.Game Rules


In this game, the player have to guess a number between 1 and 200. And he/she has a maximum of 8 attempts to guess the right number generated by the system. If he/she gives 8 wrong guesses, the game is lost and the generated number will be revealed. In both cases, the player is given the chance to retry again.


2.Code explanation


The code below represents the whole game, I will explain it step by step:



The first while loop is for repeating the game and it is a choice taken by the player at the end of the game.

The game starts by generating a number between 1 and 200 as shown below:


After that, the guessing process begins as shown below:


The player will have the chance to guess for 8 times. If he/she gives a wrong number a hint will be displayed telling if the guessed number is greater or smaller than the generated number. In the case of a right guess, a message will be displayed as well as the number of tries consumed. If the player does not guess the number in the 8 attempts, the number will be revealed and the game is lost.


Finally, as mentioned previously, the player will have the chance to repeat the game.


3.Performed test


This is a simple test performed where I succeeded to guess the number from the third try:



You can find the code repo here: https://github.com/arijbt/Data-Insight2021/blob/main/Assignments/1)Number%20Guessing%20Game-first-assignment.ipynb



1 comment

Recent Posts

See All

1 comentario


Data Insight
Data Insight
30 ago 2021

Good job!

Me gusta

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page