Magzter Gold (Sitewide Promotion)
Raspberry Pi Coding & Projects The Complete Manual (Digital)

Raspberry Pi Coding & Projects The Complete Manual (Digital)

1 Issue, Issue 2

Also available on
Zinio Unlimited logo
1-month free trial

Get unlimited access to this article, this issue, + back issues & 5,000+ other magazines.

Renews at just $8.99/month after trial.

Cancel anytime.
Learn more

Number Guessing Game

This is a simple little piece of code but it makes good use of the Random module, print and input, and a while loop. The number of guesses can be increased from 5 and the random number range can easily be altered too.
Number Guessing Game
NUMBERGUESS.PY Copy the code and see if you can beat the computer within five guesses. It’s an interesting bit of code that can be quite handy when your implementing a combination of the Random module alongside a while loop. 1 Although this is a reasonably easy to follow program, there are some elements to the code that are worth pointing out. To begin with, you need to import the Random module, as you’re using random numbers within the code. 2 This section of the code creates the variables for the number of guesses used, along with the name of the player, and also sets up the random number between 1 and 30. If you want a wider range of random number selection, then increase the number=random.randint(1, 30) end value of…
You're reading a preview of
Raspberry Pi Coding & Projects The Complete Manual (Digital) - 1 Issue, Issue 2

DiscountMags is a licensed distributor (not a publisher) of the above content and Publication through Zinio LLC. Accordingly, we have no editorial control over the Publications. Any opinions, advice, statements, services, offers or other information or content expressed or made available by third parties, including those made in Publications offered on our website, are those of the respective author(s) or publisher(s) and not of DiscountMags. DiscountMags does not guarantee the accuracy, completeness, truthfulness, or usefulness of all or any portion of any publication or any services or offers made by third parties, nor will we be liable for any loss or damage caused by your reliance on information contained in any Publication, or your use of services offered, or your acceptance of any offers made through the Service or the Publications. For content removal requests, please contact Zinio.

© 1999 – 2025 DiscountMags.com All rights reserved.