The Tech Edvocate

Top Menu

  • Advertisement
  • Apps
  • Home Page
  • Home Page Five (No Sidebar)
  • Home Page Four
  • Home Page Three
  • Home Page Two
  • Home Tech2
  • Icons [No Sidebar]
  • Left Sidbear Page
  • Lynch Educational Consulting
  • My Account
  • My Speaking Page
  • Newsletter Sign Up Confirmation
  • Newsletter Unsubscription
  • Our Brands
  • Page Example
  • Privacy Policy
  • Protected Content
  • Register
  • Request a Product Review
  • Shop
  • Shortcodes Examples
  • Signup
  • Start Here
    • Governance
    • Careers
    • Contact Us
  • Terms and Conditions
  • The Edvocate
  • The Tech Edvocate Product Guide
  • Topics
  • Write For Us
  • Advertise

Main Menu

  • Start Here
    • Our Brands
    • Governance
      • Lynch Educational Consulting, LLC.
      • Dr. Lynch’s Personal Website
      • Careers
    • Write For Us
    • The Tech Edvocate Product Guide
    • Contact Us
    • Books
    • Edupedia
    • Post a Job
    • The Edvocate Podcast
    • Terms and Conditions
    • Privacy Policy
  • Topics
    • Assistive Technology
    • Child Development Tech
    • Early Childhood & K-12 EdTech
    • EdTech Futures
    • EdTech News
    • EdTech Policy & Reform
    • EdTech Startups & Businesses
    • Higher Education EdTech
    • Online Learning & eLearning
    • Parent & Family Tech
    • Personalized Learning
    • Product Reviews
  • Advertise
  • Tech Edvocate Awards
  • The Edvocate
  • Pedagogue
  • School Ratings

logo

The Tech Edvocate

  • Start Here
    • Our Brands
    • Governance
      • Lynch Educational Consulting, LLC.
      • Dr. Lynch’s Personal Website
        • My Speaking Page
      • Careers
    • Write For Us
    • The Tech Edvocate Product Guide
    • Contact Us
    • Books
    • Edupedia
    • Post a Job
    • The Edvocate Podcast
    • Terms and Conditions
    • Privacy Policy
  • Topics
    • Assistive Technology
    • Child Development Tech
    • Early Childhood & K-12 EdTech
    • EdTech Futures
    • EdTech News
    • EdTech Policy & Reform
    • EdTech Startups & Businesses
    • Higher Education EdTech
    • Online Learning & eLearning
    • Parent & Family Tech
    • Personalized Learning
    • Product Reviews
  • Advertise
  • Tech Edvocate Awards
  • The Edvocate
  • Pedagogue
  • School Ratings
  • Kazino zīmolu un spēļu logotipu sadarbība plašās digitālajās bibliotēkās

  • Kopu formāts un tradicionālās izmaksu līnijas slotos

  • Komiksová estetika mení tón prezentácie automatových hier

  • Tipogrāfija kā tematisko spēļu automātu vizuālās identitātes daļa

  • Bonusa kārtu attīstība mūsdienu spēļu automātu stāstījumā

  • Kā turpinājumi saglabā spēles identitāti, mainot tās mehāniku

  • Kā tiešsaistes kazino piedāvā pazīstamas spēles līdzās jaunākajiem izlaidumiem

  • Kā mobilo ekrānu portreta izkārtojums mainīja spēļu automātu kompozīciju

  • Kazino spēļu vadības elementu un informācijas izkārtojuma pielāgošana dažādiem ekrāniem

  • Kā māksla un mehānika veido spēļu automātu portfeļa atšķirības

Assistive Technology
Home›Assistive Technology›How to Create a Number Guessing Game in Python

How to Create a Number Guessing Game in Python

By Matthew Lynch
June 23, 2023
0
Spread the love

Python is a popular programming language that is commonly used for developing games. Creating a number guessing game in Python is a fun and easy way to get started with game development. In this article, we will walk you through the process of creating a simple number guessing game that will allow you to build a solid foundation in Python.

Step 1: Setting up the Environment

The first step is to set up your development environment. For this project, you will need a text editor to write your Python code. There are many text editors available for free, including VS Code, Sublime Text, and PyCharm. Choose the one that you are most comfortable with and install it on your computer.

Step 2: The Code

With your text editor open, we can now begin to write the code for our number guessing game. The code we will be working with should be easy to understand, even if you are new to programming. Here is the code that you will need:

“`

import random

guessesTaken = 0

print(‘Hello! What is your name?’)

myName = input()

number = random.randint(1, 20)

print(‘Well, ‘ + myName + ‘, I am thinking of a number between 1 and 20.’)

while guessesTaken < 6:

print(‘Take a guess.’)

guess = input()

guess = int(guess)

guessesTaken = guessesTaken + 1

if guess < number:

print(‘Your guess is too low.’)

if guess > number:

print(‘Your guess is too high.’)

if guess == number:

break

if guess == number:

guessesTaken = str(guessesTaken)

print(‘Good job, ‘ + myName + ‘! You guessed my number in ‘ +

guessesTaken + ‘ guesses!’)

if guess != number:

number = str(number)

print(‘Nope. The number I was thinking of was ‘ + number + ‘.’)

“`

This code uses the `random` module to generate a random number between 1 and 20. It then asks the user to guess the number by taking input from the keyboard. It then compares the user’s guess with the generated random number and provides feedback on whether the guess is too high or too low. It also tracks the number of guesses and ends the game if the user correctly guesses the number or runs out of guesses.

Step 3: Running the Code

Once you have entered the code into your text editor, you can now run it. To do this, save the file with a `.py` extension and navigate to the directory in which you saved the file.

In your command line terminal, type `python filename.py` to run the file. For example, if you named your file `number_guessing_game.py`, you would type `python number_guessing_game.py`.

When you run the game, you should see the program ask for your name, and then it will prompt you to guess a number between 1 and 20. You can then enter a number, and the program will tell you whether your guess is too high or too low. You can continue guessing until you either guess the number correctly or run out of guesses.

Previous Article

Best Lightweight Android Browsers for Speedy Performance

Next Article

Why Thousands of Etsy Sellers Have Gone ...

Matthew Lynch

Related articles More from author

  • Assistive Technology

    Where to Watch HD Music Videos: The Best Sites

    June 11, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Use a Trackball Mouse

    June 15, 2023
    By Matthew Lynch
  • Assistive Technology

    Best Google Nest Mini Easter Eggs to Try Out

    June 9, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Make a Gantt Chart in PowerPoint

    June 14, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Use WhatsApp Web and WhatsApp on Your Computer

    June 6, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Create a Poll in Outlook

    June 11, 2023
    By Matthew Lynch

Search

Login & Registration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Newsletter

Signup for The Tech Edvocate Newsletter and have the latest in EdTech news and opinion delivered to your email address!

About Us

Since technology is not going anywhere and does more good than harm, adapting is the best course of action. That is where The Tech Edvocate comes in. We plan to cover the PreK-12 and Higher Education EdTech sectors and provide our readers with the latest news and opinion on the subject. From time to time, I will invite other voices to weigh in on important issues in EdTech. We hope to provide a well-rounded, multi-faceted look at the past, present, the future of EdTech in the US and internationally.

We started this journey back in June 2016, and we plan to continue it for many more years to come. I hope that you will join us in this discussion of the past, present and future of EdTech and lend your own insight to the issues that are discussed.

Newsletter

Signup for The Tech Edvocate Newsletter and have the latest in EdTech news and opinion delivered to your email address!

Contact Us

The Tech Edvocate
910 Goddin Street
Richmond, VA 23231
(601) 630-5238
[email protected]

Copyright © 2026 Matthew Lynch. All rights reserved.