<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: CodingNomads </title>
    <description>The latest articles on DEV Community by CodingNomads  (@codingnomads).</description>
    <link>https://dev.to/codingnomads</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F416180%2Fa1bc4e5f-e6d0-49f2-a527-f9c315ba2062.jpeg</url>
      <title>DEV Community: CodingNomads </title>
      <link>https://dev.to/codingnomads</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codingnomads"/>
    <language>en</language>
    <item>
      <title>Python Project for Beginners: Guess-the-Number Game</title>
      <dc:creator>CodingNomads </dc:creator>
      <pubDate>Thu, 12 Nov 2020 16:28:21 +0000</pubDate>
      <link>https://dev.to/codingnomads/python-project-for-beginners-guess-the-number-game-25im</link>
      <guid>https://dev.to/codingnomads/python-project-for-beginners-guess-the-number-game-25im</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this article and video, you will learn how to write a simple &lt;strong&gt;Guess-the-number game&lt;/strong&gt; in Python using a normal text editor.&lt;/p&gt;

&lt;p&gt;This tutorial is meant to be an easy Python project for beginners, so don’t worry if you don’t understand everything at first. The main point is to see that &lt;strong&gt;code is just text&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can watch the video tutorial below, and/or continue reading this blog for the written tutorial. Now let’s go build and run your first interactive Python project!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Video Tutorial: Python project for beginners&lt;/li&gt;
&lt;li&gt;Install Python on your computer&lt;/li&gt;
&lt;li&gt;
Build the Game

&lt;ul&gt;
&lt;li&gt;Coding in your text editor&lt;/li&gt;
&lt;li&gt;Save your code!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
Play the Game

&lt;ul&gt;
&lt;li&gt;Run your Python project file&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Parts of a Python project&lt;/li&gt;
&lt;li&gt;Tutorial take-aways&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Video Tutorial: Python project for beginners
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/CAOOILNwI5M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Python on your computer
&lt;/h2&gt;

&lt;p&gt;If you don’t already have Python installed on your computer, visit &lt;a href="https://www.python.org/downloads/"&gt;Python.org&lt;/a&gt; to download it. This tutorial is taught for UNIX-based systems (Mac &amp;amp; Linux). If you are on Windows and you don’t have Python pre-installed, you can also build the game in an online coding interface, such as &lt;a href="https://repl.it/"&gt;repl.it&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build the Game
&lt;/h2&gt;

&lt;p&gt;The first step in building your Python project for beginners game is to write your code in a text editor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Coding in your text editor
&lt;/h3&gt;

&lt;p&gt;Open up any Text Editor – this can be as simple as the built-in TextEdit program on MacOS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v12_-hUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/empty_textedit.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v12_-hUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/empty_textedit.png%3Fraw%3Dtrue" alt="Empty TextEdit Window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code is just plain text. So, if you’re using TextEdit, you can press Cmd+Shift+t to switch to plain text. Doing so means that you can’t apply any formatting, such as bold or italics. Remember that code is just text, so you won’t need any formatting for it. Your window should look like this now:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7G5ooOb3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/plain_textedit_window.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7G5ooOb3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/plain_textedit_window.png%3Fraw%3Dtrue" alt="Plain Text TextEdit Window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it’s time to write some code! Type the following code into your TextEdit file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random

num = random.randint(1, 10)
guess = None

while guess != num:
    guess = input("guess a number between 1 and 10: ")
    guess = int(guess)

    if guess == num:
        print("congratulations! you won!")
        break
    else:
        print("nope, sorry. try again!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you type the code exactly as you see it above, including the 4 spaces for &lt;strong&gt;indentation&lt;/strong&gt;. You can also copy-paste the code from &lt;a href="https://gist.github.com/martin-martin/d2f0bf7a6187a4e05d847b06e2bcee1d"&gt;this online resource&lt;/a&gt;. Your text window should look like this, which is already the full code for this Python project for beginners:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F2o6_Gma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/guess_code.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F2o6_Gma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/guess_code.png%3Fraw%3Dtrue" alt="Code In TextEdit Window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Save your code!
&lt;/h3&gt;

&lt;p&gt;Finally, let’s save your text file using the python file extension &lt;code&gt;.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Press Cmd+s or go to &lt;em&gt;File/Save&lt;/em&gt; and save it on your Desktop with the name &lt;code&gt;guess.py&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--laqocKOj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/finished_code.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--laqocKOj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/finished_code.png%3Fraw%3Dtrue" alt="Finised Code in TextEdit Window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that’s it for writing the code. Next step is to run the code and play your game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Play the Game
&lt;/h2&gt;

&lt;p&gt;Well done so far! &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FoKCxOx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f642.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FoKCxOx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f642.png" alt="🙂"&gt;&lt;/a&gt; To play your game on your computer you need to run the Python file you just created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run your Python project file
&lt;/h3&gt;

&lt;p&gt;To run your Python project on MacOS, open up your &lt;strong&gt;Terminal&lt;/strong&gt;. Press Cmd+Space to open up Spotlight, and type &lt;em&gt;Terminal&lt;/em&gt;, then press Enter:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--myt8C6Tx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/get_to_terminal.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--myt8C6Tx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/get_to_terminal.png%3Fraw%3Dtrue" alt="How to get to the Terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open up your Terminal, a tool that programmers use on a daily basis. If you join one of our courses, you will get to know your Terminal in much more detail, but for this beginner project you don’t need to worry about it too much. Just type the following in there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/Desktop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vsYdpbag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/cd_desktop.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vsYdpbag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/cd_desktop.png%3Fraw%3Dtrue" alt="Use cd command to move to your Desktop"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will teleport you to your Desktop, where you saved the &lt;code&gt;guess.py&lt;/code&gt; file that contains your code-text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cu0D3VXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/on_desktop.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cu0D3VXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/on_desktop.png%3Fraw%3Dtrue" alt="Terminal showing the Desktop"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you finally get to play your guess-the-number game. Since you wrote it in Python, you need to also &lt;em&gt;start&lt;/em&gt; it using Python. In your terminal, type the following and press Enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python guess.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And lo and behold! Here you are! You’ve officially built and run your very own Python project for beginners game! Now you are ready to play.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gZ_1UAMT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/played_game.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gZ_1UAMT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/played_game.png%3Fraw%3Dtrue" alt="Played Guess-the-number Game in Terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to play again after it finished, you can press the up arrow once and your terminal will show you the previous command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python guess.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pressing Enter will start the program again from the beginning.&lt;/p&gt;

&lt;p&gt;Have fun guessing the number! &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cCWgeFB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f600.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cCWgeFB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f600.png" alt="😀"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Parts of a Python project
&lt;/h2&gt;

&lt;p&gt;There are a lot of different concepts that went into creating even this simple Python project for beginners. Let’s take a look what they are:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tTury-AP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/base_parts.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tTury-AP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/base_parts.png%3Fraw%3Dtrue" alt="Base Parts of your Program"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the screenshot above you can see the &lt;strong&gt;filename&lt;/strong&gt; of the Python file you created, as well as the &lt;strong&gt;code&lt;/strong&gt; saved you saved in the file. Now let’s dive deeper into the code and learn about which &lt;strong&gt;programming concepts&lt;/strong&gt; you touched upon by making this file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fair warning&lt;/strong&gt; : There’s a lot going on! Much like a paragraph of English, a script can be broken into many parts: an introductory sentence, references to outside text, subjects, nouns, verbs, and sometimes even new vocabulary.&lt;/p&gt;

&lt;p&gt;Keep in mind that, like a paragraph of English, if you understand these parts, then it’s likely that you can write and understand another similar paragraph. Even if you haven’t seen it before. It also takes some training before you will be able to do that, so don’t feel overwhelmed if you won’t grasp it all right away. For now enjoy this depiction of the cool code you wrote! &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FoKCxOx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f642.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FoKCxOx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f642.png" alt="🙂"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s-ZZNeGQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/programming_concepts.png%3Fraw%3DTrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s-ZZNeGQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/CodingNomads/articles/blob/main/code-is-text/imgs/programming_concepts.png%3Fraw%3DTrue" alt="Highlighted Programming Concepts with Labels"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We know that is a lot of parts with a lot of colors! If you’re intrigued to learn more about writing your own Python projects, check out &lt;a href="https://codingnomads.co/courses/python-bootcamp-online/"&gt;CodingNomads Python Programming course&lt;/a&gt;. With some time and effort, you will soon be able to grasp these concepts and start speaking the coding language too!&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutorial take-aways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code is just Text&lt;/strong&gt; : Programming is just writing text, and all you need is a simple text editor to get started!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run using Python&lt;/strong&gt; : After writing your code text, you run Python programs with &lt;code&gt;python&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python project components&lt;/strong&gt; : Yes, code is just text… but is it also code &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FoKCxOx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s.w.org/images/core/emoji/13.0.0/72x72/1f642.png" alt="🙂"&gt; There are many parts of a Python project, but once you get a grasp you open the door to creating any Python project of your own.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Congratulations again on building your first Python project for beginners! If you’re interested to learn more Python coding, click below to check out CodingNomads’ Python Programming Course, and Python Career Track Course.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codingnomads.co/courses/python-bootcamp-online/"&gt;I want to learn Python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codingnomads.co/career-track/professional-python-web-development-course"&gt;I want to change careers to Python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://codingnomads.co/blog/python-project-for-beginners-guess-the-number-game/"&gt;Python Project for Beginners: Guess-the-Number Game&lt;/a&gt; first appeared on &lt;a href="https://codingnomads.co/"&gt;CodingNomads&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>learntocode</category>
      <category>python</category>
    </item>
  </channel>
</rss>
