How to Code PYTHON: Implement a *Number Guessing Game* Using a While Loop

preview_player
Показать описание
Let's get started! 🔥🔥🔥 In this video, we will write a fun PYTHON 🐍 number guessing game 🕹️ to illustrate how to increment 🔼 and decrement 🔽 a value in a looping 🔁 structure (a while loop) , which are common operations. The 1st version of the game generates a random number between 1 and 5 and allows the player to guess 😕. It keeps prompting the player for a guess until the guess is correct. Then it displays the number of guesses taken. The 2nd version of the game includes additional features like hints (too low, too high) and feedback (enter numbers only). Hope you will find this game fun! In this tutorial, you will learn some basics in less than 10 minutes!

In this video, you will learn how to:
★ 0:07 1st version - Guess a number between 1 and 5.
★ 4:16 2nd version - Guess a number between 1 and 10, with hints and feedback.

Tips and Tricks:
► Import the random module from the Python standard library to generate random numbers by calling a function in that module.
► count += 1 is just a shortened form of count = count + 1. The += operator takes the current value of count, adds 1, and then assigns the new value back into count.
► It is always a good practice to validate user inputs. In this game, we check to make sure the input is a valid number with the isnumeric function.
► Make sure the string input (guess) is casted to an integer before it is used to compare with the random integer number (value).

WANT MORE PYTHON TUTORIALS?
🐍 Python Coding for Beginners:

For the setup, please read the followings before you begin:
2. Install Python and remember to select "Add Python... to PATH" when asked.
4. Install the Python extension for Visual Studio Code: Go to View and select Extensions, or select the Extensions icon, then search for python.

👇 SUBSCRIBE TO CODING WITH KIDS 👨🏻‍💻👩🏻‍💻 YOUTUBE CHANNEL NOW 👇

#CodingWithKids #PythonProgramming #PythonForBeginners
Рекомендации по теме
Комментарии
Автор

👦🏻👧🏻 Welcome to CODING WITH KIDS!
Hope you'll enjoy coding in PYTHON!

CodingWithKids