<?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: Vicki Langer</title>
    <description>The latest articles on DEV Community by Vicki Langer (@vickilanger).</description>
    <link>https://dev.to/vickilanger</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%2F169425%2F48b84fd1-2234-47cd-a498-7be383beb8bb.jpeg</url>
      <title>DEV Community: Vicki Langer</title>
      <link>https://dev.to/vickilanger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vickilanger"/>
    <language>en</language>
    <item>
      <title>TIE: What is an MVC framework?</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Mon, 25 Apr 2022 18:14:20 +0000</pubDate>
      <link>https://dev.to/vickilanger/tie-what-is-an-mvc-framework-3g1o</link>
      <guid>https://dev.to/vickilanger/tie-what-is-an-mvc-framework-3g1o</guid>
      <description>&lt;p&gt;&lt;em&gt;Explaining concepts that can be hard to understand. You can expect relatable examples without jargon, &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;bar&lt;/code&gt;, and math examples.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Jump to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Official explanation&lt;/li&gt;
&lt;li&gt;TechItEasy explanation&lt;/li&gt;
&lt;li&gt;More Info&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have you heard of this MVC thing? If not, you might look it up and run into a description like this. ⬇️ 😬 If you'd like an easier to understand explanation, you're welcome to jump down to the TechItEasy explanation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scary Jargon-filled Explanation &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;MVC (Model-View-Controller) is a pattern in software design commonly used to implement user interfaces, data, and controlling logic. It emphasizes a separation between the software's business logic and display. This "separation of concerns" provides for a better division of labor and improved maintenance.&lt;/p&gt;

&lt;p&gt;The three parts of the MVC software-design pattern can be described as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Model: Manages data and business logic.&lt;/li&gt;
&lt;li&gt;View: Handles layout and display.&lt;/li&gt;
&lt;li&gt;Controller: Routes commands to the model and view parts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;source: &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/MVC" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/US0y4X7FONHaM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/US0y4X7FONHaM/giphy.gif" alt="Simba and Nala from the lion king looking at each other like something doesn't make sense."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Does this chart make sense? If not, I bet it will once you're done reading this TechItEasy explanation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FGlossary%2FMVC%2Fmodel-view-controller-light-blue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FGlossary%2FMVC%2Fmodel-view-controller-light-blue.png" alt="Controllers contain logic and they change models. Models are the definitions of data structures and they change the views. Views define UI and they send info to the controllers. Controllers sometimes send info back to the views."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TIE: MVC framework &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/mFNCEWjufpRJa8XLCj/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/mFNCEWjufpRJa8XLCj/giphy.gif" alt="Moira from Schitts Creek saying "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Wait! What's a Framework?
&lt;/h3&gt;

&lt;p&gt;Glad you asked. We should probably know that before we get into some real life examples.&lt;/p&gt;

&lt;p&gt;A framework is a set of pre-made pieces used to help speed up building and give a standard way to make applications. These pre-made pieces of code are typically called components. Frameworks can include components for user management. User management may include creating, reading, updating, deleting, send forgotten password emails, etc. Frameworks are helpful because they remove the need to write code for things that get used all the time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Use Frameworks?
&lt;/h4&gt;

&lt;p&gt;If you haven't heard it before, DRY stands for Don't Repeat Yourself. This is an ideology that says we shouldn't have to write the same code multiple times. If you wrote code on how to make a cat, you wouldn't want to write it again and again for every cat that comes into existence. In this way, MVC has components that make it so the common things don't have to be written again. MVC frameworks help keep your code DRY.&lt;/p&gt;

&lt;p&gt;Of note, MVC frameworks follow a pattern to help you think of each part of an app separately. There are other design patterns, but it seems &lt;a href="https://trends.builtwith.com/framework" rel="noopener noreferrer"&gt;MVC frameworks are most common&lt;/a&gt;. I'd guess they're common for a reason. &lt;/p&gt;

&lt;p&gt;MVC frameworks simplify the building process. That's not to say it's easy, but to mean that it's generally easier than building a whole web app without a framework.&lt;/p&gt;

&lt;h4&gt;
  
  
  Right, now, What are the M, V, and C?
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Models
&lt;/h5&gt;

&lt;p&gt;Models are like a template or chart for data/info needed for an item or object. For example, if your pet has data. Some of the data is needed and some is nice to have but not required. Models allow you to say what each piece of data is whether or not it is required, and lots of other things. Here's a table representing a dog model.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;&lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi"&gt;Date Type&lt;/a&gt;&lt;/th&gt;
&lt;th&gt;Required?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pet_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi#words"&gt;string&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;spayed_neutered&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi#bool"&gt;boolean&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;weight_lbs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi#nums"&gt;number&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;favorite_toy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each name in this table represents a column in a database. You could imagine it looking like this.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;pet_name&lt;/th&gt;
&lt;th&gt;spayed_neutered&lt;/th&gt;
&lt;th&gt;weight_lbs&lt;/th&gt;
&lt;th&gt;favorite_toy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Cheeto&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;11.1&lt;/td&gt;
&lt;td&gt;BALL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Remmy&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;12.8&lt;/td&gt;
&lt;td&gt;fishing pole&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Wiley&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;32.3&lt;/td&gt;
&lt;td&gt;beheaded dragon&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Chip&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;0.00440925&lt;/td&gt;
&lt;td&gt;crashed helicopter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;Beans&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;9.6&lt;/td&gt;
&lt;td&gt;random piece of foam&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice we've added IDs. Sometimes these are referred to as &lt;code&gt;uid&lt;/code&gt; which is short for "unique identifier". In this case, each new pet is given a number that belongs to them. We use an ID because everything else can change and we need to have access to reference the specific pet.&lt;/p&gt;

&lt;h5&gt;
  
  
  Views
&lt;/h5&gt;

&lt;p&gt;Views are the code behind the pretty stuff. This is your front-end user interface code. It's generally some combination of HTML and CSS. It can also be done in other languages that get rendered/translated into HTML and CSS.&lt;/p&gt;

&lt;h5&gt;
  
  
  Controller
&lt;/h5&gt;

&lt;p&gt;Controllers do the controlling. Good? Make sense? No? I didn't think so. Controllers are where you'll write code on how things should work. This is where the logic goes. &lt;/p&gt;

&lt;h5&gt;
  
  
  Okay, but How Do They Work Together?
&lt;/h5&gt;

&lt;p&gt;Controllers change models. Models change the views. Views send info to the controllers. Controllers sometimes send info back to the views. For extra confusion, models also talk to databases. Are you confused yet? How about we jump into some real-life MVC frameworks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example with Your Body
&lt;/h3&gt;

&lt;p&gt;Whether you knew it or not, your body has models, views, and controllers.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/521dYs81zApnq/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/521dYs81zApnq/giphy.gif" alt="Dancing skeleton on a dark red stage"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Models
&lt;/h4&gt;

&lt;p&gt;You could look at your skeleton as a model. Your bones define the shape and structure of your body. Regardless of what bones you do and don't have, they are your model. By themselves, bones don't do anything but give structure. If you want the bones to look pretty, you'll need your views. For them to do things, you'll need controllers. &lt;/p&gt;
&lt;h4&gt;
  
  
  Views
&lt;/h4&gt;

&lt;p&gt;Next time you get out of the shower, look in a mirror or take a selfie. What you see is your view. For your body, the view is your physical appearance. Your view includes skin, textures, colors, hair, and anything else that naturally exists as part of you. This would be like the HTML structure of a web page. &lt;/p&gt;

&lt;p&gt;If you choose to, you may put clothes on, use prosthetics, move parts to get the right shape, use jewelry, use assistive devices, or do any number other things to change the outward appearance of your body. This is very similar to using CSS to make a webpage more interesting.&lt;/p&gt;

&lt;p&gt;Views can send info to controllers. In the case of your body, you could imagine that something happened or you sensed that it happened. For example, a mosquito may land on you. Whether you saw it or felt it, this was your body's view send data to your controller.&lt;/p&gt;
&lt;h4&gt;
  
  
  Controller
&lt;/h4&gt;

&lt;p&gt;Your brain contains your controllers. Your brain houses all of the logic for your body. If a mosquito landed on you, your &lt;code&gt;avoid_mosquito_bite&lt;/code&gt; controller is then going to send out a job for you to move your limbs and address the intruder. &lt;/p&gt;

&lt;p&gt;Your brain knows how to handle things because you have taught or coded it to do them. You may not recall, but at some point you may have learned how count, read, brush your teeth, and all of your other daily tasks.&lt;/p&gt;

&lt;p&gt;There are also controllers for things you never had to learn. They came pre-coded. Most of the time, we have the ability to breathe, process food, pump blood, and all sorts of other body processes. These pre-coded bodily functions are similar to an MVC framework's pre-built controllers for things like login and user profiles. &lt;/p&gt;
&lt;h4&gt;
  
  
  Now for How They Work Together
&lt;/h4&gt;

&lt;p&gt;If you've lived this long, I think it's safe to assume you know your skin works with your skeleton and your brain and vice versa. &lt;/p&gt;

&lt;p&gt;Your brain (controller) uses logic to tell your skeleton to move in certain ways. When your skeleton (model) has been told to move, your skin (view) moves and changes with it. When your skin receives input from the outside world, it will send a message to the brain. From there, the brain may tell the skeleton to move a different way.&lt;/p&gt;

&lt;p&gt;Your skeleton (model) may also talk to a database. In this case, we could call your memory the database. Every time your brain tells your skeleton to change shapes, your memory saves it for future reference. &lt;/p&gt;

&lt;p&gt;I think, at this point, this chart may make a little bit more sense. What do you think? &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FGlossary%2FMVC%2Fmodel-view-controller-light-blue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FGlossary%2FMVC%2Fmodel-view-controller-light-blue.png" alt="Controllers contain logic and they change models. Models are the definitions of data structures and they change the views. Views define UI and they send info to the controllers. Controllers sometimes send info back to the views."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Still having trouble? Try thinking of the sites you use regularly. Their controllers will likely include actions like creating, reading, updating, and deleting. The models are going to be the things those actions happen to (ie characters, posts, products, etc). The views are the pretty (or maybe not) visual part you see on your browser.&lt;/p&gt;


&lt;h2&gt;
  
  
  Other Things Worth Knowing &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;There are plenty of options when it comes to MVC frameworks. There are even multiples for different languages. Here are a few popular ones and the official getting started projects.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;th&gt;More Info&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;Django&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.djangoproject.com/en/4.0/intro/tutorial01/" rel="noopener noreferrer"&gt;Polls tutorial&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ruby&lt;/td&gt;
&lt;td&gt;Rails&lt;/td&gt;
&lt;td&gt;&lt;a href="https://guides.rubyonrails.org/getting_started.html" rel="noopener noreferrer"&gt;Blog Tutorial&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Angular JS&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.angularjs.org/tutorial" rel="noopener noreferrer"&gt;Catalog tutorial&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.NET&lt;/td&gt;
&lt;td&gt;ASP.NET&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?WT.mc_id=dotnet-35129-website&amp;amp;view=aspnetcore-6.0&amp;amp;tabs=visual-studio" rel="noopener noreferrer"&gt;ASP.NET Getting Started&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PHP&lt;/td&gt;
&lt;td&gt;Laravel&lt;/td&gt;
&lt;td&gt;&lt;a href="https://laravel.com/docs/4.2/quick" rel="noopener noreferrer"&gt;Laravel Quickstart&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;MVC frameworks make it easier and quicker to create full stack apps than it would be if you wrote everything from scratch. It will take some time to learn how things are put together, but you will reap the reward of being able to make things relatively quickly. Once you've got the basics, congrats! You're a full stack developer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/RbDKaczqWovIugyJmW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/RbDKaczqWovIugyJmW/giphy.gif" alt="Yellow bird tapping at a keyboard with lots of techy haxxor things flying around them"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Btw, what's TIE?
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/vickilanger" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F169425%2F48b84fd1-2234-47cd-a498-7be383beb8bb.jpeg" alt="vickilanger"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/vickilanger/tie-what-is-tech-it-easy-tie-4h28" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;TIE: What is Tech It Easy (TIE)?&lt;/h2&gt;
      &lt;h3&gt;Vicki Langer ・ Mar 21 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#codenewbie&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>TIE: What is a Cascading Delete?</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Tue, 22 Mar 2022 15:45:39 +0000</pubDate>
      <link>https://dev.to/vickilanger/tie-what-is-a-cascading-delete-with-relatable-examples-378i</link>
      <guid>https://dev.to/vickilanger/tie-what-is-a-cascading-delete-with-relatable-examples-378i</guid>
      <description>&lt;p&gt;&lt;em&gt;Explaining concepts that can be hard to understand. You can expect relatable examples without jargon, &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;bar&lt;/code&gt;, and math examples.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Jump to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Official explanation&lt;/li&gt;
&lt;li&gt;TechItEasy explanation&lt;/li&gt;
&lt;li&gt;More Info&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Scary Jargon-filled Explanation &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In a relational database, a foreign key with cascade delete means that if a record in the parent table is deleted, then all associated records in the child tables will automatically be deleted. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TIE: Cascading Delete &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/flflBfU5JhR8k/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/flflBfU5JhR8k/giphy.gif" alt="A gif showing a waterfall in bordered by lots of rock and the beautiful leaves of fall" width="480" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, we must mention, cascading deletes are used with databases who are made up of tables. Deleting means to remove something. Cascades are like waterfalls. So, imagine a delete that flows and takes out all the things attached to the item being deleted.&lt;/p&gt;

&lt;p&gt;Let's try out on few ideas to make sure there is a relatable explanation that fits you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example at the Vet Clinic
&lt;/h3&gt;

&lt;p&gt;A customer has moved and you need to delete an owner from owners_table and all of their pet records that are in different tables. Here you would used a cascading delete to remove the owner and all of their pets.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example in Social Media
&lt;/h3&gt;

&lt;p&gt;The most important part of a social media site, like MySpace, is made up of users and their posts. This means there is a table with all users and a table with all posts. Let's say user XxDinoHottie13xX has 379 posts. Before you ask, yes, they are mostly shit posts. &lt;/p&gt;

&lt;p&gt;If XxDinoHottie13xX decides they no longer want to have an account on MySpace, they click on a delete button. When they click on the delete button, what do you think should delete? With a cascading delete, it will delete the user, their posts, and anything else that is attached or owned by that user.&lt;/p&gt;




&lt;h2&gt;
  
  
  Other Things Worth Knowing &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;There are soft and hard deletes. A cascading delete is a type of hard delete, the data is gone forever. A soft delete hides data from view, but keeps it in the background. Data that is soft deleted is often given a &lt;code&gt;deleted_at&lt;/code&gt; column.&lt;/p&gt;

&lt;p&gt;If there is any possible reason the data being deleted may be needed in the future, a cascading delete may be a bad idea. Sometimes this reason can be as simple as "we need to know that we had the record at one point in time".&lt;/p&gt;

&lt;p&gt;You may think about your placing files in your computer's recycle bin as a soft delete. Then when you empty the bin and it asks you if you want to "permanently erase the items". If you say yes, you've done a hard delete.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qhMNnIuN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfbf1a0c45gsj9o5v6vp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qhMNnIuN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfbf1a0c45gsj9o5v6vp.png" alt="Screenshot of mac dialog box. &amp;quot;Are you sure you want to permanently erase the items in the Trash. you can't undo this action." width="526" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the social media example, a hard delete would be one where all of a users data is permanently removed. A soft delete would be like deactivating the account. A soft delete would keep all the data but make it hidden from the actual site.&lt;/p&gt;


&lt;h2&gt;
  
  
  Btw, what's TIE?
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/vickilanger" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YXTevQJr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--AYh2gEQo--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/169425/48b84fd1-2234-47cd-a498-7be383beb8bb.jpeg" alt="vickilanger"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/vickilanger/tie-what-is-tech-it-easy-tie-4h28" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;TIE: What is Tech It Easy (TIE)?&lt;/h2&gt;
      &lt;h3&gt;Vicki Langer ・ Mar 21 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#codenewbie&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>beginners</category>
    </item>
    <item>
      <title>TIE: What is Tech It Easy (TIE)?</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Mon, 21 Mar 2022 16:52:56 +0000</pubDate>
      <link>https://dev.to/vickilanger/tie-what-is-tech-it-easy-tie-4h28</link>
      <guid>https://dev.to/vickilanger/tie-what-is-tech-it-easy-tie-4h28</guid>
      <description>&lt;p&gt;Hi! Welcome! Have you ever had a hard time understanding a code or programming concept? Then you're in the right place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jump to
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
What is TechItEasy 👀 &lt;/li&gt;
&lt;li&gt;Are there Rules?&lt;/li&gt;
&lt;li&gt;
Some TechItEasy Do's &amp;amp;&amp;amp; Don'ts

&lt;ul&gt;
&lt;li&gt;Asking&lt;/li&gt;
&lt;li&gt;Answering&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
Where is TechItEasy? &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is TechItEasy? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;TechItEasy is a developer community built to resemble Reddit's &lt;a href="https://www.reddit.com/r/explainlikeimfive/"&gt;Explain Like I'm Five (ELI5)&lt;/a&gt; subreddit. If you're not familiar with it, ELI5 is a forum with requests for concepts to be explained in jargon-free simplified terms. &lt;/p&gt;

&lt;p&gt;TechItEasy is your place to ask about those things you just cannot comprehend, have a hard time understanding, and could really use some help with.&lt;/p&gt;

&lt;p&gt;TechItEasy is also your place to help others understand concepts that you know.&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--JzS7wHjq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1445098918098972676/VsVbAUhd_normal.jpg" alt="Vicki Langer profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Vicki Langer
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @vicki_langer
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Hey friends, do you have something you're having or had trouble understanding and you'd like explained in a relatable way?&lt;br&gt;&lt;br&gt;Tweet to this community and start your tweet with "TIE: " then add your question.&lt;br&gt;&lt;br&gt;Example: "TIE: What is control flow and how does it work?"
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      19:51 PM - 02 Mar 2022
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1499110207921741824" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1499110207921741824" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=1499110207921741824" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  A Few Basic Rules &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/MpjvaamQCOOw7eCtar/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MpjvaamQCOOw7eCtar/giphy.gif" alt='A person in a spooky background saying "best get some consistent rules"' width="480" height="270"&gt;&lt;/a&gt;&lt;br&gt;
➡️ Do start Tweets with &lt;code&gt;TIE:&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This will keep TechItEasy tweets easy to recognize and search for.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;➡️ Do give relatable explanations without scary tech jargon&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Some ideas: cats, doing dishes, weather, music, cutting vegetables, cats knocking over trashcans, games, reading, and so so so many other things&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;➡️ Keep tweets on topic&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tweets shall only include Requests for Explanations, Suggestions or Complaints, or Praise. Tweets should add to the community and not distract from the purpose.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;➡️ Avoid vague Requests for Explanation&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;(e.g. "TIE: What is Programming?", "TIE: What causes this error?", )&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;➡️ Be respectful &amp;amp;&amp;amp; Report the jerks&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We are all human. We are not perfect. If someone is wrong, kindly help them understand, tag someone to help explain, or just ignore it.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Some Do's &amp;amp;&amp;amp; Don'ts &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Asking Questions &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Do ask...&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for help understanding a concept, idea, or how things work&lt;/li&gt;
&lt;li&gt;for explanations in relatable terms&lt;/li&gt;
&lt;li&gt;your question even if you think it's "simple" or "should be easy". I promise, there are others that don't understand either&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Good Examples&lt;/em&gt;&lt;br&gt;
✨ TIE: What is control flow and how does it work?&lt;br&gt;
✨ TIE: What is a cascading delete?&lt;br&gt;
✨ TIE: How is a tuple different from a list?&lt;br&gt;
✨ TIE: Why does 0.1 + 0.2 not equal to 0.3?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't ask...&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for opinions&lt;/li&gt;
&lt;li&gt;controversial or loaded questions&lt;/li&gt;
&lt;li&gt;for anyone to do your homework&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Bad Examples&lt;/em&gt;&lt;br&gt;
🚫 TIE: Light or dark mode?&lt;br&gt;
🚫 TIE: What language should I start with&lt;br&gt;
🚫 TIE: What is Programming?&lt;/p&gt;

&lt;h3&gt;
  
  
  Answering Questions &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Do&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;assume zero prior experience&lt;/li&gt;
&lt;li&gt;use relatable examples (ideas)
&lt;/li&gt;
&lt;li&gt;use descriptive names&lt;/li&gt;
&lt;li&gt;avoid &lt;a href="https://en.wikipedia.org/wiki/Circular_definition"&gt;circular definitions&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Good Examples&lt;/em&gt;&lt;br&gt;
✨ watermelon_count = (5 - spoiled_watermelons) / people&lt;br&gt;
✨ A customer has moved and you need to delete an &lt;code&gt;owner&lt;/code&gt; from &lt;code&gt;owners_table&lt;/code&gt; and all of their &lt;code&gt;pet&lt;/code&gt; records that are in different tables. Here you would used a cascading delete to remove the owner and all of their &lt;code&gt;pets&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't...&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;bar&lt;/code&gt;, or other non-descriptive names&lt;/li&gt;
&lt;li&gt;use math examples (unless the the original poster is a mathematician)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Bad Examples&lt;/em&gt;&lt;br&gt;
🚫 x = (5 - y)/2&lt;br&gt;
🚫 &lt;code&gt;baz&lt;/code&gt; has many &lt;code&gt;foo&lt;/code&gt; and if we want to delete &lt;code&gt;foo&lt;/code&gt; and all associated records, we'd call that a cascading delete&lt;/p&gt;




&lt;h2&gt;
  
  
  Where do I start? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ejpCynLi88pGEUbmvQ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ejpCynLi88pGEUbmvQ/giphy.gif" alt='Some doodled cat-like figures bowing down and saying "one of us"' width="480" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember, start questions with &lt;code&gt;TIE:&lt;/code&gt; and make sure answers are as simplified as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Twitter
&lt;/h2&gt;

&lt;p&gt;Join us in the &lt;a href="https://twitter.com/i/communities/1499095889104752646"&gt;TechItEasy&lt;/a&gt; community on Twitter. From there it's up to you to ask a question or answer someone else's. I look forward to seeing you there. &lt;/p&gt;

&lt;h2&gt;
  
  
  Other places, like right here on Dev.to
&lt;/h2&gt;

&lt;p&gt;Create a new post, start your title with &lt;code&gt;TIE:&lt;/code&gt;, then tag your post with &lt;code&gt;#help&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VmmhnLzN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg7tlvbyxdg6gz3tkefh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VmmhnLzN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg7tlvbyxdg6gz3tkefh.png" alt="Screenshot of dev.to post with the title starting  with  raw `TIE:` endraw  and tagged with the  raw `#help` endraw  tag" width="880" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Charming Python with Lists</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Thu, 06 Jan 2022 14:22:05 +0000</pubDate>
      <link>https://dev.to/vickilanger/charming-python-with-lists-1139</link>
      <guid>https://dev.to/vickilanger/charming-python-with-lists-1139</guid>
      <description>&lt;p&gt;&lt;em&gt;If learning to code with &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;bar&lt;/code&gt;, and math examples are your kryptonite, keep reading. This series uses relatable examples like flipping coins, books, bread, and groceries.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Don't forget, while writing your code, there are &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970"&gt;lots of tools there to help you&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Jump To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are Data Structures&lt;/li&gt;
&lt;li&gt;Indexing&lt;/li&gt;
&lt;li&gt;Slicing&lt;/li&gt;
&lt;li&gt;Mutability&lt;/li&gt;
&lt;li&gt;Nested Lists&lt;/li&gt;
&lt;li&gt;Let's Build!&lt;/li&gt;
&lt;li&gt;Practice Challenges&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are Data Structures &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Data structures are collections or groups of data. Typically, data structures hold data types and other data structures. Think of data structures as boxes that have certain rules for what can go in them. You can fit other boxes inside this box as well as other things too.&lt;/p&gt;

&lt;p&gt;Python has two types of data structures. There are primitives, which you already learned about, and there are collections. Data types, or primitives, include the basic structures we talked about earlier: integers, floats, strings, and boolean. Primitives also include a type called &lt;code&gt;complex&lt;/code&gt;. We haven’t and won’t go over these as they are used in very few things (eg electrical engineering, physics, etc). Oftentimes, we will want to group primitives together. We do this using collections.&lt;/p&gt;

&lt;p&gt;Collections allow us to group objects with similarities together. A collection can hold as many objects as you want. Objects can be primitives or collections. Yes, we can put collections inside of other collections. Then we can even put that collection of collections in another collection. I’m sure that was super confusing, but don’t worry. We will go over this in detail later in the section about nesting.&lt;/p&gt;

&lt;p&gt;For now, let’s stick to talking about what the built-in data structures are. In Python, we have lists, dictionaries, sets, and tuples. You can build, or implement, data structures of your own (eg stack, queue, tree, etc), but we really should continue learning the fundamentals first. First up, shall we talk about lists?&lt;/p&gt;

&lt;h2&gt;
  
  
  Lists
&lt;/h2&gt;

&lt;p&gt;Lists are exactly what they sound like. They help you group similar things or objects together. Typically these things have something in common. You’ve used them in real life whether you realize it or not. Lists also have the benefit of being ordered or numbered. We’ll talk about this soon.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-life examples
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l0MYv61yrzZu6roFG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l0MYv61yrzZu6roFG/giphy.gif" alt="Snoopy from The Peanuts shuffling cards and looking sude to side skeptically"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Keeping track of scores in a card game
&lt;/h4&gt;

&lt;p&gt;You likely start with a blank piece of paper. Even though it’s empty, we could call it a list because we know you’re about to write down scores for the game. Each time someone gains points, you add them to the end of the list. Tada! You have a list with values on it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Have you ever made and used a grocery list?
&lt;/h4&gt;

&lt;p&gt;You likely start with a blank piece of paper. Even though it’s empty, we could call it a list because we know you’re about to write down items we need to get at the store. Every time you think of something you need at the store, you add it to your list. Tada! You have a list with values on it.&lt;/p&gt;

&lt;p&gt;Now for the important part of that grocery list. You’re at the store. Every time you find an item and put it in your basket, you can remove the item from your list. Hopefully, by the time you’re done, the list will be empty.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;Lists can have any number of items or even zero items. You’ll find that since a list is often expected to have multiple items, its name will typically be plural. Many times, you’ll see each item and its comma on a separate line. For space reasons, most of our example lists will be on one line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# make an empty list
&lt;/span&gt;&lt;span class="n"&gt;pets_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="c1"&gt;# list with items
&lt;/span&gt;&lt;span class="n"&gt;my_scores_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;54&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;your_scores_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc38t8m1fmld5mweokerc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc38t8m1fmld5mweokerc.png" alt="screenshot of python tutor showing the above code with each integer in each list labelled 0-4, starting at 0"&gt;&lt;/a&gt;&lt;br&gt;
Lists can contain any mix of data structures, variables, and hard-coded data. This means we can have lists inside of lists, but again, we'll go over that shortly in the section about nesting. For now, know that we can include any mix of variables and hard-coded data in a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;flipper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;spatula&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;chopper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;knife&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;scooper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;spoon&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;stabber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fork&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;cooking_equipment_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;flipper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chopper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scooper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stabber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bowl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34n90l6hep5emgvo8pmy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34n90l6hep5emgvo8pmy.png" alt="screenshot of python tutor showing the above code with each object in the list labelled 0-4, starting at 0"&gt;&lt;/a&gt;&lt;br&gt;
Make note that even though you gave the list the variables, the list used the variables to find the actual value of each variable.&lt;/p&gt;

&lt;p&gt;Did you notice anything weird about how the list items show up in Python Tutor or the screenshots? The items are numbered, but what number was given to the first item in the list?&lt;/p&gt;
&lt;h4&gt;
  
  
  Relearn How To Count with Zero-Based Numbering  &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycghz2pmxwinfud6xqa4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycghz2pmxwinfud6xqa4.png" alt="graphic showing a list of tools. first tool is labelled 0, second tool is labelled 1, third tool is labelled 2, and 4th tool is labelled 3"&gt;&lt;/a&gt;&lt;br&gt;
Typically, when we learn to count we start from 1, right? In Python, and most other programming languages, we start counting from zero. We call this zero-based numbering. This means the first thing in your list will always be at the position, or index, zero.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xt2q9wlvy40ftwdllab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xt2q9wlvy40ftwdllab.png" alt="graphic showing a list of tools. first tool is labelled 0 and -4, second tool is labelled 1 and -3, third tool is labelled 2 and -2, and 4th tool is labelled 3 and -1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By the way, we can also index backwards, using negative numbers. This would make the last item in your list index position -1 and the second to last item in your list index position -2. This can help when you are trying to get an item from the end of your list.&lt;/p&gt;
&lt;h5&gt;
  
  
  Finding your Maximum Index
&lt;/h5&gt;

&lt;p&gt;This also means your last index position will always be one less than the length of your list. Do you know why? Look at the &lt;code&gt;cooking_equipment_list&lt;/code&gt; above. It is 5 items long and its last or biggest index is 4. You’ll find it is common to save &lt;code&gt;len(list) - 1&lt;/code&gt; into a variable called &lt;code&gt;max_index&lt;/code&gt; or &lt;code&gt;last_index&lt;/code&gt;. This will become helpful soon when we learn how to get items from a list. This could look like &lt;code&gt;last_index = len(box_contents_list) - 1&lt;/code&gt; and it could be read as “the last index is the length of the box_contents_list minus one”.&lt;/p&gt;

&lt;p&gt;Of course, if you know how long the list is, you could hard-code the length. This will work at first, but what if you add to the list later? If you hard-code it, you would have to go back and fix this part too. This could become painful, especially with longer lists where we don’t know the length or if other people are adding to the list and didn’t know something else needed to be changed too.&lt;/p&gt;
&lt;h3&gt;
  
  
  What can we do with lists?
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Getting an Index
&lt;/h4&gt;

&lt;p&gt;What is this “getting” you speak of? A lot of programming is based on the computer’s ability to get things and set things. Getting means that you have asked for the item and setting means you have changed an item. Let’s use hobbies as an example. Just like when we made a list, when we want to get or set indices, we use &lt;code&gt;[]&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Ceora has some hobbies
&lt;/span&gt;&lt;span class="n"&gt;music&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;K-pop&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;curiosity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;asking awesome questions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;ceora_hobbies_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;music&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;curiosity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;memes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;advocacy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DX&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hamilton&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# get hobby from index 2
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hobby at index 2:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ceora_hobbies_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# set/change/update then print hobby at index 2
&lt;/span&gt;&lt;span class="n"&gt;ceora_hobbies_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Philly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;changed hobby at index 2:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ceora_hobbies_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# get hobby from second to last index
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2nd from last index:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ceora_hobbies_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you notice we used the same index for the first two sections after creating the list? This is on purpose. In the first section, we want to “get the current hobby at index 2 and print it”. In the next part, we want to “set or change the hobby at index 2 and print it” to verify that it changed. The last bit is just showing how we can use negative indices.&lt;/p&gt;

&lt;p&gt;You could also choose to get the index and save it into a variable like this code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# get hobby from index 2
&lt;/span&gt;&lt;span class="n"&gt;hobby_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ceora_hobbies_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hobby at index 2:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hobby_3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you haven’t already, go ahead and give this indexing a try before moving forward.&lt;/p&gt;

&lt;h5&gt;
  
  
  Slicing  &lt;a&gt;&lt;/a&gt;
&lt;/h5&gt;

&lt;p&gt;If you ever wanted a certain portion of a list, you can get it by cutting from one position to another. We call this slicing. Let’s say we have a loaf of bread and we want all the slices, except the pieces on either end. You might initially think we need to know how many slices there are, but we don’t.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6e4vr0ngk3hgv8qbpy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6e4vr0ngk3hgv8qbpy8.png" alt="2 loaves of different kinds of bread with some slices cut and a knife"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the parts of the loaf we want, we can use slicing. Slicing also uses &lt;code&gt;[]&lt;/code&gt; but it requires more info. When slicing, you’ll use square brackets with two numbers in between. The two numbers will be separated by a colon &lt;code&gt;:&lt;/code&gt;. It should look like this &lt;code&gt;[2:7]&lt;/code&gt;. This would mean you want everything from index 2 up to but not including index 7.&lt;/p&gt;

&lt;p&gt;From what we know so far, there are multiple ways we could get all slices of bread without the end pieces. We will need to combine slicing with either negative indexing or the max index that we talked about earlier. Let’s see how this can be done both ways. I think it’s time to make a sandwich, what do you think?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# get sandwich bread 2 different ways
&lt;/span&gt;&lt;span class="n"&gt;bread_loaf_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;end piece&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;other end piece&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# use slicing with negative indexing
&lt;/span&gt;&lt;span class="n"&gt;bread_loaf_without_ends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bread_loaf_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sandwich bread retrieved with negative indexing:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bread_loaf_without_ends&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# use slicing with max index
&lt;/span&gt;&lt;span class="n"&gt;last_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bread_loaf_list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;different_loaf_without_ends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bread_loaf_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;last_index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sandwich bread retrieved with max index:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;different_loaf_without_ends&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice, &lt;code&gt;-1&lt;/code&gt; and the &lt;code&gt;last_index&lt;/code&gt; variable refer to the same index position and they are &lt;strong&gt;not&lt;/strong&gt; included in the sliced section you asked for.&lt;/p&gt;

&lt;p&gt;We used two different ways to get the same result. Remember, there are often different ways things can be done with code. This means there is no one right way to do things, but there are some guidelines on why we would choose one way over another. There are two main goals when deciding which way to code something. Generally, we prioritize readability or how easy this code is to read without assistance. The other goal is performance or how quickly the computer can read and process the code. This is important, but not near as important as being able to understand the code. When you’re learning, prioritize readability and you can learn about performance later. For readability, you could also have chosen to use loops to iterate through the list.&lt;/p&gt;

&lt;h4&gt;
  
  
  Iterating
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/FGnCkFfcHXaGk/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/FGnCkFfcHXaGk/giphy.gif" alt="car continuously driving around a loop de loop rollercoaster style"&gt;&lt;/a&gt;&lt;br&gt;
If you don’t recall what a &lt;a href="https://dev.to/vickilanger/a-bit-more-dry-with-loops-14hn."&gt;loop&lt;/a&gt; is, you can always go back to refresh your memory Or, take a look at this example and see if it’s enough to conjure up the memory. Remember, “iterating” and “running a loop” are used interchangeably where one iteration is one use of the loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;bread_loaf_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;end piece&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;other end piece&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# get sandwich bread a 3rd way, with a loop
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nb"&gt;slice&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bread_loaf_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;slice&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run this example, clicking the “next” button in Python Tutor will show you what happens at each step.&lt;/p&gt;

&lt;p&gt;Here we have a list, the same one we used before. Then we are using a loop to say “I want to look at the first piece of the loaf to check if it is a &lt;code&gt;slice&lt;/code&gt;. If it is a &lt;code&gt;slice&lt;/code&gt;, it will get printed with a comma and a space &lt;code&gt;,&lt;/code&gt; after it.” That would be one iteration. After our first iteration, we’ve checked the first piece of bread. The loop then moves to the next piece and does the same thing as it did the first time. Then it repeats until it gets to the last item in the list.&lt;/p&gt;

&lt;p&gt;Printing is fun and all, but let’s see what else we can do with lists.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some Methods You Can Use with Lists
&lt;/h4&gt;

&lt;p&gt;We have a bunch of list methods.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;append(item)&lt;/code&gt; - adds an item to the end of a given list&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;insert(index, item)&lt;/code&gt; - adds a given item at a given position&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pop(index)&lt;/code&gt; - remove and return the item at the given position in the list&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;count(item)&lt;/code&gt; - return the number of times a given item is in the list&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reverse()&lt;/code&gt; - reverse order of the list&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;clear()&lt;/code&gt; - remove all items from the list&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt;
Unlike string methods that give you a new string, list methods actually change the list you’re working with. This happens because lists are mutable and strings are immutable. Mutable means that it can change or mutate. Immutable means it cannot change or it cannot mutate. Lists being mutable or changeable is incredibly helpful. Think about your real-life lists. We’re constantly adding to them, removing things, counting the items, and so much more. Python allows us to do all of these things.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60aexms8zhf695e2ci0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60aexms8zhf695e2ci0n.png" alt="Lots and lots of different people of different ages, colors, and abilities reading books"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In real life, a chalkboard or notebook would be mutable and art in a museum would be considered immutable. A published book could also be considered immutable, but plans for reading a book may be changed based on different things.&lt;/p&gt;

&lt;p&gt;Here is a list example with some examples of methods. Try running the making of the list and start by running each method separately to see what happens. If you run all methods at once, the final output will include all of the methods performed in the order they were given. Once you’ve run each one individually, try figuring out what the end result should be. Then go ahead and add them together and see what the end result is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;prologue_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Once upon a time, I yelled at an alpaca while riding a motorcycle.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;chapter_1_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I jumped on a birdbath in a library because a zebra told me to.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;chapter_2_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Then, I kicked a pickle on a table because I found 1,000 gold bars&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;chapter_3_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I sang to a spoon in line at the bank because I can&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t control myself!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;cat_picture_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;planned_reading_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prologue_str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chapter_1_str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chapter_2_str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# you have extra time, let's read chapter 3 too
&lt;/span&gt;&lt;span class="n"&gt;planned_reading_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chapter_3_str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# never mind, you don't have time for the list chapter
&lt;/span&gt;&lt;span class="n"&gt;planned_reading_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# oh wait, there was a picture after chapter 1
&lt;/span&gt;&lt;span class="n"&gt;planned_reading_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cat_picture_str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# want to see how goofy the book is backward?
&lt;/span&gt;&lt;span class="n"&gt;planned_reading_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# anyway, how many items are "cat"?
&lt;/span&gt;&lt;span class="n"&gt;cat_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;planned_reading_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cat_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# done reading? Clear your reading to-do list
&lt;/span&gt;&lt;span class="n"&gt;planned_reading_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
​​&lt;/p&gt;

&lt;p&gt;By the way, if you had even more reading to do, you can also add multiple lists together. Try making some lists and adding them together. When you add them together, they will be in the order you typed them. In the example below, &lt;code&gt;not_mammals_list&lt;/code&gt; will be first, then &lt;code&gt;mammals_list&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;mammals_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dog&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;not_mammals_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;snake&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fish&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;animals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;not_mammals_list&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;mammals_list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Nesting Lists  &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Remember earlier when I mentioned lists could be inside lists? We call these nested lists or a list of lists. Why would we even need that? Let’s talk about a couple of examples.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynwh5spw7nbk87othjvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynwh5spw7nbk87othjvm.png" alt="a picture of a door separates into a kitchen and a laundry room. the laundry room separates into different items from the laundry room. from the laundry room, we have a basket with lots of dirty clothes in it"&gt;&lt;/a&gt;&lt;br&gt;
Think of a home as a list of lists. How could you categorize a home? Rooms could be lists inside the home. Then things inside the room could be items in the room’s list. If one of the rooms has a cabinet, that would be another list, and items inside the cabinet could be items in the cabinet list.&lt;/p&gt;

&lt;p&gt;You could also look at a book as a nested list. You can run this code or make something similar that makes sense to you. In Python Tutor, it will draw arrows to show you where each of the lists is being used. You can hover your mouse over the arrows to highlight them. If it’s getting confusing, Try commenting out a chapter or two. Once you understand what is happening you can add them back in one at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# some sentences
&lt;/span&gt;&lt;span class="n"&gt;sentence_1_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;jumped&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;birdbath&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;library&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;because&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bird&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;told&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;me&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;to.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sentence_2_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;karate&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chopped&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pickle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;the&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dinner&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;table&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;because&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;someone&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;offered&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;me&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1,000,000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gold&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bars&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sentence_3_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sang&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;spoon&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;line&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;the&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bank&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;because&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;can&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;control&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;myself!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sentence_4_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yelled&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;an&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;alpaca&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;while&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;riding&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;motorcycle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;because&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;like&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;getting&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wet.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sentence_5_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;glamorous&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;alien&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;squashed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;an&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;angry&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,]&lt;/span&gt;
&lt;span class="n"&gt;sentence_6_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;scrawny&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;elephant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;squeezed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slimy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;doctor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,]&lt;/span&gt;

&lt;span class="c1"&gt;# some chapters that contain sentences
&lt;/span&gt;&lt;span class="n"&gt;chapter_1_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;sentence_1_list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentence_2_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;chapter_2_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;sentence_3_list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentence_4_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;epilogue_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;sentence_5_list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentence_6_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# a book that contains chapters that contains sentences
&lt;/span&gt;&lt;span class="n"&gt;book_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;chapter_1_list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chapter_2_list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;epilogue_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# want to see the goofy story backward?
&lt;/span&gt;&lt;span class="n"&gt;book_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Indexing Nested Lists
&lt;/h5&gt;

&lt;p&gt;What if we wanted the 3rd item of the 4th list of the 1st list? Remember indexing? We can index nested lists too! It looks like this &lt;code&gt;home_list[-1][3][21]&lt;/code&gt;. This would read something like “I want the last list in &lt;code&gt;home_list&lt;/code&gt;. Then I want the item from index position 3 or the 4th item in that list. Now that I have that list, I want the object from index 21.” Try the below code with your nested list practice. Can you guess what it is before you run the code?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# get 2nd item from booklist, then 2nd item from that item, then 2nd item from that item
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# get 1st item from booklist, then the third from last item from that item, then 3rd item from that item
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Getting indices from nested lists can be confusing. Try reading them one index at a time and that should help. There’s really no limit to how many indices there can be other than the capability of the computer.&lt;/p&gt;

&lt;p&gt;Were nested lists hard to understand? If so, don’t be hard on yourself. They’re a more advanced concept. You can absolutely keep coding and come back to these later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s Build Mad Libs  &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://towardsdatascience.com/a-i-plays-mad-libs-and-the-results-are-terrifying-78fa44e7f04e" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2ADtHJdDR_nYfo4E1YBAMdHQ.png" alt="Picture of a 1982 mad lib: the magic computers: today, every student has a computer small enough to fit in his "&gt;&lt;/a&gt;&lt;br&gt;
Mad Libs are stories with words removed and replaced by blanks where you get to fill in the words and make a goofy story. Typically, the blanks are labeled and meant for certain types of words like verbs or adjectives. For this, we will make some lists, then choose words based on an index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# make some lists of available words
&lt;/span&gt;&lt;span class="n"&gt;verbs_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yelled&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;swam&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;vanished&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kicked&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slept&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;questioned&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;scattered&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;escaped&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chased&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;jumped&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;adjectives_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slimy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gooey&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;jumpy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;melted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;damaged&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fierce&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;victorious&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sparkling&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rotten&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fluffy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;nouns_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;donkey&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sidewalk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;zebra&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cactus&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;playground&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;toothbrush&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;celery stalk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;umbrella&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bottle of poison&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ghost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;adverbs_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;seemingly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;suspiciously&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;foolishly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;greedily&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;famously&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;viciously&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;awkwardly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cleverly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;recklessly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;frantically&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# get some user input
&lt;/span&gt;&lt;span class="n"&gt;your_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s your name?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Give a number 1-10&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# Publish your story using indices
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;your_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;adverbs_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;verbs_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nouns_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nouns_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First we made our lists. Then we ask a user for their name and a number. We forced the number input to be an integer because it is a string by default. Next, we subtract 1 from the number they gave because in most programming languages we start counting at 0. Lastly, we used a print statement and list indexing to build our story.&lt;/p&gt;

&lt;p&gt;This story is less than perfect. The strings in the print statement don’t always work because those words should change based on the chosen words from the lists. Still, this does show us a way to use lists and how to use indices. I bet you know enough to use code to help make decisions on which words to use. Do you remember what kind of statements we use to &lt;a href="https://dev.to/vickilanger/if-this-then-that-585#flow"&gt;make decisions&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;All of our words are hard-coded and it really would be better if they were filled in randomly. Later, we will go over how to make this into a random sentence generator.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s Build a Better Coin-Flipping Game
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/uWdISK26Bn8aFT832p/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/uWdISK26Bn8aFT832p/giphy.gif" alt="Black person flipping a coin. The coin goes up a little before the it falls back to the person's hand"&gt;&lt;/a&gt;&lt;br&gt;
Do you recall how we talked about making a &lt;a href="https://dev.to/vickilanger/dry-out-with-loops-d6l/"&gt;functional program then adding features later&lt;/a&gt;? We’re going to do that again. Our first rendition of this coin-flipping game was only a few lines then we added scoring. Now, we’re going to use lists to make this game even better.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0 at beginning
&lt;/span&gt;&lt;span class="n"&gt;rounds_lost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0 at beginning
&lt;/span&gt;&lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0 at beginning
&lt;/span&gt;&lt;span class="n"&gt;coin_landed_possibilities_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;heads&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tails&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;game_results_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;  &lt;span class="c1"&gt;# starting a list to keep track of results
&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;your_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Heads or Tails?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;coin_landed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coin_landed_possibilities_list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# you can change this index
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;coin_landed&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;your_choice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You win this round&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;game_results_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;won&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lost this round&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rounds_lost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rounds_lost&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;game_results_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;lost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# calculate who won
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You win! You got best 2 out of 3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lose! Computer got best 2 out of 3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# print results summary
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;summary of games:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;game_results_list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a little better, right? We can keep track of our wins and losses with &lt;code&gt;game_results_list&lt;/code&gt;. The &lt;code&gt;coin_landed&lt;/code&gt; is no longer a string, but it is still hardcoded. The coin is always going to land on heads unless you changed it to a different index. Later, when we go over modules, we’ll talk about how to make &lt;code&gt;coin_landed&lt;/code&gt; random. We’ll also talk about how to code a fix for what happens if someone types in something you don’t expect, like “kitties jumping on a trampoline.”. In reality, we know people are unlikely to type that, but they may type “hedds” or “tales”.&lt;/p&gt;

&lt;p&gt;Did you see how we started that empty list? We call this “initializing a list”. It’s very much like getting out a piece of paper to start a list. You want to start or initialize this list so that it is ready for you to add things to it later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why lists and when to use them?
&lt;/h3&gt;

&lt;p&gt;Lists allow us to categorize things by similarities and they work well with loops. Now would be a great time to go back to the loop section to see if you can make those fake list examples into real lists that work. Don’t forget lists are ordered or numbered. This helps us when creating, reading, updating, and deleting things because we can specify exactly where you want these actions to take place.&lt;/p&gt;




&lt;h2&gt;
  
  
  Do you remember? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here's some practice challenges. Let’s practice what we’ve learned so far. Go ahead and comment on this post with your answers. Do you remember? If not, you can always go back to read sections again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Give an example of a list, then follow these steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Make a list of something you might do in real life&lt;/li&gt;
&lt;li&gt;Get rid of the second to last item&lt;/li&gt;
&lt;li&gt;Flip the order of your list&lt;/li&gt;
&lt;li&gt;Make everything in your list uppercase&lt;/li&gt;
&lt;li&gt;Add something to the end of the list&lt;/li&gt;
&lt;li&gt;Add something to the middle of the list using the max index&lt;/li&gt;
&lt;li&gt;Flip the order of your list&lt;/li&gt;
&lt;li&gt;Add an item at position 1&lt;/li&gt;
&lt;li&gt;Empty your list&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Show us:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# what your beginning list was
&lt;/span&gt;
&lt;span class="c1"&gt;# the code you made
&lt;/span&gt;
&lt;span class="c1"&gt;# the list you ended up with. 
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Was there anything that didn’t work? Do you know why?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Can You Fix What’s Wrong with This?
&lt;/h3&gt;

&lt;p&gt;There may be more than one way to fix each line of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;drawer_top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;voltage&lt;/span&gt; &lt;span class="n"&gt;tester&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;wire&lt;/span&gt; &lt;span class="n"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;electrical&lt;/span&gt; &lt;span class="n"&gt;tape&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;drawer_middle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="n"&gt;inch&lt;/span&gt; &lt;span class="n"&gt;sockets&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ratchet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;inch&lt;/span&gt; &lt;span class="n"&gt;sockets&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;drawer_bottom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tape&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt; &lt;span class="n"&gt;ties&lt;/span&gt;&lt;span class="p"&gt;,]&lt;/span&gt;
&lt;span class="n"&gt;tool_box&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;drawer_top&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;. drawer_mid&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;drawer_bottom&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,}

drawer_left = [safety glasses| gloves| mask| ear plugs]
drawer_right = [hammer/ stud finder/ pencil/ scribe,]
work_bench = [drawer_left, drawer_right]

garage_list = [work_bench tool box, shelf]

# I need a 1/2 inch socket to take tire off bike
garage_list[2]{2][3)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How would you read that last line out loud?&lt;/p&gt;

&lt;h3&gt;
  
  
  Go Ahead! You can build a game of chance
&lt;/h3&gt;

&lt;p&gt;Using the coin-flipping game as an example, try making something like &lt;a href="https://wrpsa.com/the-official-rules-of-rock-paper-scissors/" rel="noopener noreferrer"&gt;Rock Paper Scissors&lt;/a&gt;. Remember, to make the game work first, then add the extra stuff like lists and scoring. If something doesn’t work, no worries that’s normal. Go back to the &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970#debug"&gt;How Do I Code? Error section&lt;/a&gt; for help figuring out the errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# scoring for a game using lists
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thanks to &lt;a class="mentioned-user" href="https://dev.to/ceeoreo"&gt;@ceeoreo&lt;/a&gt; for allowing use of their beautiful name.&lt;/p&gt;

&lt;p&gt;All of my gratitude to &lt;a class="mentioned-user" href="https://dev.to/yechielk"&gt;@yechielk&lt;/a&gt; for reviewing yet another post. If you like learning about how ethics and programming go together from a Talmudic perspective, check out their &lt;a href="https://torahandtech.dev/" rel="noopener noreferrer"&gt;newsletter and book&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>challenge</category>
      <category>python</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>DRY Out with Loops</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Wed, 29 Dec 2021 13:32:52 +0000</pubDate>
      <link>https://dev.to/vickilanger/dry-out-with-loops-d6l</link>
      <guid>https://dev.to/vickilanger/dry-out-with-loops-d6l</guid>
      <description>&lt;p&gt;&lt;em&gt;If learning to code with &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;bar&lt;/code&gt;, and math examples are your kryptonite, keep reading. This series uses relatable examples.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Jump To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
For Loops

&lt;ul&gt;
&lt;li&gt;Real-life For Loops&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

While Loops

&lt;ul&gt;
&lt;li&gt;Real-life While Loops&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Practice Challenges&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;A loop is a set of instructions that gets continually repeated a certain amount of times or until a condition is met. A condition could be waiting for something to be true or false. A condition could also refer to waiting on the loop to run enough times. Let’s go through a pseudocode example of doing introductions in a new group of people. After that, we’ll talk about different types of loops.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# repeat these steps for every person in the group
# say hi
# give your name and pronouns
# say what you like to do when you’re bored
# mention something you could talk about for hours
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  For Loops
&lt;/h2&gt;

&lt;p&gt;Sometimes we do know exactly how many times we want to repeat our steps or run a loop. When this is the case, we should use a &lt;code&gt;for&lt;/code&gt; loop. This doesn’t mean &lt;em&gt;you&lt;/em&gt; need to know the exact number of times to repeat the code. I know that sounds contradictory, but I promise it’s not. Knowing the exact number of times to repeat the code can mean that you used some code to explain how many times. We often use &lt;code&gt;len()&lt;/code&gt; and &lt;code&gt;range()&lt;/code&gt; to get the exact number of repetitions. We’ll go over how &lt;code&gt;range()&lt;/code&gt; works then jump into some examples.&lt;/p&gt;

&lt;p&gt;From the Python documentation, &lt;code&gt;range()&lt;/code&gt; gives a “sequence of numbers and is commonly used for looping a specific number of times in for loops.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;range(startNum=0, stopNum, step=1)&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;startNum&lt;/code&gt; is the beginning of your range. It’s not required. The default is &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;stopNum&lt;/code&gt; is the end of your range.&lt;/li&gt;
&lt;li&gt;Give only the &lt;code&gt;stopNum&lt;/code&gt; and you will get that many numbers, though it will not include the &lt;code&gt;stopNum&lt;/code&gt;. This is because computers start counting at 0 and not 1.&lt;/li&gt;
&lt;li&gt;Give &lt;code&gt;startNum&lt;/code&gt; and &lt;code&gt;stopNum&lt;/code&gt; and you’ll get numbers from &lt;code&gt;startNum&lt;/code&gt; to &lt;code&gt;stopNum&lt;/code&gt;, but not including &lt;code&gt;stopNum&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;step&lt;/code&gt; is like counting by 2s (2, 4, 6, 8). If you give it &lt;code&gt;5&lt;/code&gt; it will give you every 5th number.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# get numbers up to, but not including 100
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you notice how there is space in front of all the lines underneath the &lt;code&gt;for&lt;/code&gt; line? These are just like the &lt;code&gt;if&lt;/code&gt; blocks. The tab before the line is how Python knows this line is a step that belongs to the loop. The next line(s) that are &lt;strong&gt;not&lt;/strong&gt; tabbed in are not part of a loop and therefore will not be repeated. They will run after the loop is done because computers read code top to bottom.&lt;/p&gt;

&lt;p&gt;I would read this example as: “for each number from (or “in the range of”) 0 up to but not including 100 while skipping 20, print the number”. The example code would run 5 times. Do you know why? &lt;code&gt;range()&lt;/code&gt; is giving us our exact number of times to run the loop. The range starts at 0, ends at but doesn’t include 100, and counts by or steps over 20. In this case, we get 0, 20, 40, 60, and 80.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is &lt;code&gt;i&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;You’ll find outside of giving the syntax above, I will never use &lt;code&gt;i&lt;/code&gt;. I find it easier to understand my code when I use a descriptive name. A name is great, but we still need to know what the elusive &lt;code&gt;i&lt;/code&gt; is. In a &lt;code&gt;for&lt;/code&gt; loop, &lt;code&gt;i&lt;/code&gt; is a variable that only gets used within the loop.&lt;/p&gt;

&lt;p&gt;This variable is called an iterator variable. It is created in the &lt;code&gt;for&lt;/code&gt; line, then it can be used in the block of loop code. With each repetition/iteration of the loop, any uses of the variable in the loop block will change. If the first repetition, the iterator variable was &lt;code&gt;0&lt;/code&gt;, then in the second repetition the iterator variable was &lt;code&gt;1&lt;/code&gt;, and so on.&lt;/p&gt;

&lt;p&gt;To make things easier to understand, we could just have easily used &lt;code&gt;num&lt;/code&gt; or &lt;code&gt;digit&lt;/code&gt; instead of &lt;code&gt;i&lt;/code&gt;. Read the syntax to yourself, substituting one of these for the &lt;code&gt;i&lt;/code&gt;. Does it make a bit more sense now? Diving into some real-life examples should help explain this better.&lt;/p&gt;

&lt;p&gt;Do know that if you’re working with books, tutorials, videos, or even other programmers, they may choose to use &lt;code&gt;i&lt;/code&gt;. Know that when you’re reading it, you can substitute what makes sense to you.&lt;/p&gt;

&lt;h3&gt;
  
  
  What can we do with &lt;code&gt;for&lt;/code&gt; loops?
&lt;/h3&gt;

&lt;p&gt;Again, &lt;code&gt;for&lt;/code&gt; loops should be used when we want to repeat code and we know how many times to repeat it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Real-life examples &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Have you ever washed dishes before? I have and I really don’t enjoy it. Let’s try setting up some code for a dishwashing robot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# assume we have a list or sink full of 37 dirty dishes called dirty_dishes_list
# for every dish on the counter, wash it
&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;dish&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;dirty_dishes_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;add_soap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;scrub_dish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;rinse_dish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;dry_dish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dish&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;has been cleaned&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This DishBot 3000 code won’t work because none of these functions have been made. Instead, they are placeholders in an example. If you want to see it work, you could swap each line for a line like: &lt;code&gt;print("DishBot 3000 has added soap")&lt;/code&gt;. We are also missing a &lt;code&gt;dirty_dishes_list&lt;/code&gt;. Once you learn about lists, come back to this example, make a &lt;code&gt;dirty_dishes_list&lt;/code&gt;, and try out the code.&lt;/p&gt;

&lt;p&gt;Since DishBot 3000 is done washing dishes, I think it’s time to make some more dirty dishes while making dinner. Shall we read our recipe and write up some pseudocode?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1u7rvxlyiz60icptv6zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1u7rvxlyiz60icptv6zl.png" alt="3 people making food. first one is a Black person holding a recipe stirring a pot on the stove. next is a tan woman stirring a pot on the stove. last is a white person mixing stuff in a bowl with a whisl"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# recipe pseudocode
&lt;/span&gt;
&lt;span class="c1"&gt;# put all ingredients in a bowl
# mix for two minutes
&lt;/span&gt;
&lt;span class="c1"&gt;# heat stove and dump mixed ingredients in pot on stove
# mix for five minutes
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With our pseudocode recipe done, we can figure out what our code should be. How many of those steps include some sort of repetition? For each step with repetition, we will need another separate loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# recipe loops
&lt;/span&gt;
&lt;span class="c1"&gt;# put all ingredients in a bowl
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;ingredient&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ingredients_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ingredient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;measured&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ingredient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;added to bowl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# mix for two minutes
&lt;/span&gt;&lt;span class="n"&gt;bowl_mix_minutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;minute&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bowl_mix_minutes&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mixed ingredients for 1 minute&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# heat stove and dump mixed ingredients in pot on stove
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Stove is turned on&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Mixture has been added to the pot&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# mix for two more minutes
&lt;/span&gt;&lt;span class="n"&gt;stove_mix_minutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;minute&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stove_mix_minutes&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mixed ingredients over heat for 1 minute&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These loop examples won’t work as expected because we are using lists, but haven’t made any lists. We’ll talk about lists soon and you can come back to see how these work out.&lt;/p&gt;

&lt;p&gt;Do you recall why the stove heating print statements are not part of any of these loops? If not, hop back to the for loop syntax for a refresher.&lt;/p&gt;

&lt;h4&gt;
  
  
  Code Behind the &lt;code&gt;.upper()&lt;/code&gt; method
&lt;/h4&gt;

&lt;p&gt;Earlier, we talked about the &lt;code&gt;.upper()&lt;/code&gt; method. This method takes a string and makes all of the characters uppercase. You now know enough things to write the magic behind &lt;code&gt;.upper()&lt;/code&gt;. Let’s pseudocode it first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pseudocoding .upper()
&lt;/span&gt;
&lt;span class="c1"&gt;# save a string into a variable
# for every character in the string
# if the character is lowercase
# make the character uppercase and print
# if the character is a space, print the space
# if none of that (meaning the character is already uppercase), print the character
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that you have this written out in pseudocode, use the steps to guide you in writing some code. Don’t forget, you can turn your pseudocode into comments to explain each line. Another hint, programmers tend to use &lt;code&gt;char&lt;/code&gt; because it’s short for “character”.&lt;/p&gt;

&lt;p&gt;If you don’t recall the ASCII codes for all of the letters, that’s cool, I don’t either. Flip back to &lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi#words"&gt;String Built-in Functions&lt;/a&gt; or lookup &lt;a href="https://www.google.com/search?q=ascii+letter+chart" rel="noopener noreferrer"&gt;“ASCII letter chart”&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Did you notice our pseudocode used the words &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;if&lt;/code&gt;? We can mix and match our spoken language with the programming language. This helps us start to form an idea of what we should be coding.&lt;/p&gt;

&lt;p&gt;I bet you’ll recall that we use tabs and code blocks in both &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;if&lt;/code&gt; blocks. If you use them together, you’ll use combine the tabs to show Python you intend for one to be a part of another. For example, if you have an &lt;code&gt;if&lt;/code&gt; block as part of your for loop, the &lt;code&gt;if&lt;/code&gt; line will have one tab to show it is part of the &lt;code&gt;for&lt;/code&gt; loop. Then, the lines that are part of the &lt;code&gt;if&lt;/code&gt; block have two tabs to show it is part of the &lt;code&gt;if&lt;/code&gt; block that is inside a &lt;code&gt;for&lt;/code&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# coding .upper()
&lt;/span&gt;
&lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I smelled a goat at the store because I&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;m a snowman!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# for every character in the string
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;97&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;122&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# if the character is lowercase
&lt;/span&gt;        &lt;span class="n"&gt;new_char_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;  &lt;span class="c1"&gt;# get the uppercase character code
&lt;/span&gt;        &lt;span class="n"&gt;new_char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_char_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# use new_char_code to get uppercase letter
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# print new_char with no space at end
&lt;/span&gt;    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# if char is a space
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# if none of the above (probably: char already uppercase or not a letter)
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the way, you can combine functions together. Taking existing code and modifying it to be easier to read and more efficient is called refactoring. With the above example, we could refactor a few lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# original lines
&lt;/span&gt;&lt;span class="n"&gt;new_char_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;  &lt;span class="c1"&gt;# get the uppercase character code
&lt;/span&gt;&lt;span class="n"&gt;new_char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_char_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# use new_char_code to get uppercase letter
&lt;/span&gt;
&lt;span class="c1"&gt;# possible replacement
&lt;/span&gt;&lt;span class="n"&gt;new_char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# get uppercase character code then get letter
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why &lt;code&gt;for&lt;/code&gt; loops and when to use them?
&lt;/h3&gt;

&lt;p&gt;Without loops, we would have to write a lot more code. That would be a hassle for you, the programmer, and your computer would have bigger files to hold on to. Remember, we use &lt;code&gt;for&lt;/code&gt; loops when we can discern exactly how many times we need to repeat the code.&lt;/p&gt;




&lt;h2&gt;
  
  
  While Loops &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes we really don’t know how many times we want to repeat our steps. When this is the case, we should use a &lt;code&gt;while&lt;/code&gt; loop. This means no programmer knows the exact number of times to repeat the code.&lt;/p&gt;

&lt;p&gt;Have you ever hit "repeat" on a song? That is a while loop. It's going to repeat until you tell it to stop or until there is no power left for the device. If we were coding, we could say "while there is power, play the song on repeat".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/QoD2PAumUHCz6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/QoD2PAumUHCz6/giphy.gif" alt="Dog from Nickelodeon's Doug cartoon listening to music with headphones while bobbing their head and looking at comic books"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;something_true&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are several steps to a while loop. If you skip one of them, your while loop is likely to mess up. Remember, the computer will do what you tell it to, not what you want it to do.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the counter - a variable to help know when the loop should end&lt;/li&gt;
&lt;li&gt;Give a condition - comparison or logical operator, similar to an if statement&lt;/li&gt;
&lt;li&gt;Increment or Decrement the counter - add/subtract every time the loop runs&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Avoid Infinite Loops &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;An infinite loop means code repeats forever until your computer senses it and stops the code. This will often look like your computer or a single program is crashing and not responding. If this is the case, you may need to close the tab or program. Then, go back to your code and make sure you have incremented the counter.&lt;/p&gt;

&lt;h3&gt;
  
  
  What can we do with &lt;code&gt;while&lt;/code&gt; loops?
&lt;/h3&gt;

&lt;p&gt;Again, &lt;code&gt;while&lt;/code&gt; loops should be used when we want to repeat code and we don’t know how many times to repeat it. Instead, we give a comparison(s) or logical operator(s) to make a condition.&lt;/p&gt;

&lt;h4&gt;
  
  
  Real-life examples  &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkoybrlukib08omzf8nm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkoybrlukib08omzf8nm.png" alt="person holding and petting a cat. sun with clouds. dog chasing a ball"&gt;&lt;/a&gt;&lt;br&gt;
Have you ever pet a cat before? Most cats are a perfect example of a while loop. Before we start, let’s ask the cat how many times they’d like to be pet. We aren’t going to tell the human doing the petting. We’re just going to use the cat’s answer to define our condition. To ask the cat for this, we will use &lt;code&gt;input()&lt;/code&gt;. Sadly, we need a number, and &lt;code&gt;input()&lt;/code&gt; gives us strings. So, we have to force the it into a number using &lt;code&gt;int()&lt;/code&gt;. This forcing from string to integer is called &lt;a&gt;&lt;/a&gt;“casting a string to an integer”. All together, we can save the cat’s response into a variable using the first line in this example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# first ask the cat how many times they’d like to be pet, but don’t tell the human
&lt;/span&gt;&lt;span class="n"&gt;preferred_pets_num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How many times would you like to be pet&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;pet_attempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0
&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;preferred_pets_num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;pet_attempts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You have consent to pet again&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;purrrr, that pet was accepted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;pet_attempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pet_attempts&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;# add 1 every time you pet
&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;That was 1 too many times. I&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;m leaving now&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The three tabbed in lines run once for each repetition of the loop. The loop ends when we have gone over the accepted amount of pets. Now that the loop is over, we can print that the cat has decided to leave.&lt;/p&gt;

&lt;p&gt;Now that the cat is upset and has left us, let’s check the weather and see if our dog is ready to play. In this example, we’ll combine a bunch of the things we’ve covered like &lt;a href="https://dev.to/vickilanger/if-this-then-that-585"&gt;if-then statements&lt;/a&gt;, &lt;a href="https://dev.to/vickilanger/if-this-then-that-585#condition"&gt;logical operators&lt;/a&gt;, &lt;a href="https://dev.to/vickilanger/a-bit-more-dry-with-loops-14hn#casting"&gt;casting strings&lt;/a&gt;, and a while loop. It’s longer than some of the other examples. We’ll look at the different parts to make it make sense.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dog_wants_to_play&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;  &lt;span class="c1"&gt;# dog always wants to play
&lt;/span&gt;&lt;span class="n"&gt;sunny_outside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sunny? True/False&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;rainy_outside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Raining? True/False&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;warm_outside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Warm outside? True/False&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;cold_outside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Cold outside? True/False&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;  &lt;span class="c1"&gt;# starting with 100%
&lt;/span&gt;&lt;span class="n"&gt;outside_spent_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;  &lt;span class="c1"&gt;# % energy spent fetching one time
&lt;/span&gt;&lt;span class="n"&gt;inside_spent_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="c1"&gt;# % energy spent fetching one time
&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# gotta leave pup some energy
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sunny_outside&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;warm_outside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;go_outside&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# sets outside to True
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;outside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;throw_ball&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Go get it!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Drop it&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;outside_spent_energy&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;rainy_outside&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;cold_outside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;throw_ball&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# throw carefully, you're inside
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Go get it!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;inside_spent_energy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;At the top, first chunk of lines, we have some inputs that will later help us decide when and where to play. I would read the second line as: “getting user input string of True or False, cast or force into a boolean, then saved into variable &lt;code&gt;sunny_outside&lt;/code&gt;”. &lt;/li&gt;
&lt;li&gt;After the inputs, we have three lines that set up our dog’s energy. I’d read these as “dog starts with 100% energy, 3% energy is spent outside, and 2% energy is spent inside.” Now we can get into our while loop. Our first line of the loop could read as “while the dog has more than 50% energy, then we do the stuff below”.&lt;/li&gt;
&lt;li&gt;Looks like we’ve run into an if-elif statement. Depending on the inputs, you’ll only do one or the other. There are two options: “If it’s sunny and warm, then do the code in this block” or “If it’s rainy or cold, then do the code in this block”.&lt;/li&gt;
&lt;li&gt;At the end of each of the if and elif blocks, we made sure to account for spent energy and subtract from dog’s energy. You could read that line as “current dog’s energy is now &lt;code&gt;=&lt;/code&gt; the old dog’s energy minus energy spent”. Without this line, we’d have an infinite loop and our poor dog would be so tired they may get hurt.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do know, this code won’t work as is because none of these functions have been made. Instead, they are placeholders in an example. If you want to see it work, you could swap each fake function (&lt;code&gt;go_outside()&lt;/code&gt; and &lt;code&gt;throw_ball()&lt;/code&gt;) for a line like: &lt;code&gt;print("We are outside now.")&lt;/code&gt;. You would also have to change &lt;code&gt;if outside:&lt;/code&gt; to &lt;code&gt;if True:&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We talked about infinite loops earlier, but they’re generally a computer or human problem. There are infinite loops in real life. Do you know about the water cycle? The basic concept doesn’t have a good starting point because it is always happening. So, let’s start with rain, snow, and any other precipitation. Water, in some form, falls from the sky. Then, this water collects somewhere (eg bucket, ocean, lake etc). Once the water collects, it can evaporate. As it evaporates, clouds form and the cycle continues until the end of Earth.&lt;/p&gt;

&lt;p&gt;If you run try writing this code, expect it to crash. If you don’t remember why that’s fine. You can jump back to the section on &lt;a href="https://dev.to/vickilanger/a-bit-more-dry-with-loops-14hn#infinite"&gt;infinite loops&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;earth_exists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="c1"&gt;# while the earth_exists
# water falls back to earth - precipitate
# water collects
# water evaporates
# clouds form - condensation
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Behind the Scenes: Winning and Losing
&lt;/h4&gt;

&lt;p&gt;Using while loops and if-else statements we can build scoring for your favorite game. No matter the complexity of the scoring, you can write it with while loops and if-else statements. First, we’ll use a coin-flipping game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/SABvdsgeZrcu4SbdA6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/SABvdsgeZrcu4SbdA6/giphy.gif" alt="white person flipping a United States quarter. The coin looks like it is coming at you then there are words "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our first step won’t be in a while loop. We’ll add the loop when we adjust the game to have 3 rounds and whoever gets two out of 3 will win. Coins have two sides. We’ll call one side “heads” and the other “tails”. Player one, the computer, flips the coin while player two, you, say which side they think will land facing up. If player two’s choice has landed facing up, they win.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;your_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Heads or Tails?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;coin_landed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;heads&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;coin_landed&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;your_choice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You win&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now, we have “hard coded” which side of the coin landed facing up. Hard coding means that we did not use any programming magic to come up with this. Instead, we told it the answer. Later when we talk about Python lists, we will add a couple of things to make the computer’s coin flipping random.&lt;/p&gt;

&lt;p&gt;For now, we know who won this game but we should make this fair and try for the best two out of three rounds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0
&lt;/span&gt;&lt;span class="n"&gt;rounds_lost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0
&lt;/span&gt;&lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# start with 0
&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;your_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Heads or Tails?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;coin_landed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;heads&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;# you can change this
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;coin_landed&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;your_choice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You win this round&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lost this round&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;rounds_lost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rounds_lost&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# calculate who won
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total_rounds&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;rounds_won&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You win! You got best 2 out of 3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lose! Computer got best 2 out of 3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;At the top, the first chunk of lines, we added in some counters to help run the code.&lt;/li&gt;
&lt;li&gt;After the counters, we added a while loop and tabbed in the if-else statements and their blocks.&lt;/li&gt;
&lt;li&gt;With the &lt;code&gt;input().lower()&lt;/code&gt; we are acknowledging that a player may input something with different capitalization and we are making sure it will match out &lt;code&gt;coin_landed&lt;/code&gt; exactly.&lt;/li&gt;
&lt;li&gt;Looks like we’ve run into an if-else statement. Depending on the outcome of the round, you’ll only do one or the other. There are two options: “the coin side facing up is the same as your choice, then do the code in this block” or “the coin side facing up is not the same as your choice, then do the code in this block”.&lt;/li&gt;
&lt;li&gt;At the end of each of the if and else blocks, we made sure to account for the results of the round. Depending on the block, you could read that line as “current rounds won &lt;code&gt;=&lt;/code&gt; the old rounds won plus one” or “current rounds lost &lt;code&gt;=&lt;/code&gt; the old rounds lost plus one”.&lt;/li&gt;
&lt;li&gt;After the else block, but still part of the while loop, we add one to our total rounds. Without this line, we’d have an infinite loop and our game would never end.&lt;/li&gt;
&lt;li&gt;At the very end, after the loop ends, we use another if-else statement to decide who won the whole game.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Did you notice how we coded the important guts of the game first, then we added the extra features? This is a typical approach to coding. First, we build a functional project. Once it works, we can add features to it. This helps us keep from getting overwhelmed and allows us to see working parts sooner.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why &lt;code&gt;while&lt;/code&gt; loops and when to use them?
&lt;/h3&gt;

&lt;p&gt;Remember, we use &lt;code&gt;while&lt;/code&gt; loops when we cannot know exactly how many times we need to repeat the code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Do you remember? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here's some practice challenges. Let’s practice what we’ve learned so far. Go ahead and comment on this post with your answers. Do you remember? If not, you can always go back to read sections again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Give a real-life example of a &lt;code&gt;for&lt;/code&gt; loop and a &lt;code&gt;while&lt;/code&gt; loop
&lt;/h3&gt;

&lt;p&gt;You can use print statements or fake functions (like &lt;code&gt;jump()&lt;/code&gt; or &lt;code&gt;turn_wheel()&lt;/code&gt;) to fill in the if-elif-else then blocks&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# coding a for loop
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# coding a while loop
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What’s Wrong with These? Can You Fix them?
&lt;/h3&gt;

&lt;p&gt;There may be multiple ways to fix these. Have fun and do it whatever way you think makes sense.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pets are a mix of birds, fish, cats, dogs, and reptiles
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;pet&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="nf"&gt;feed_pet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;brush_pet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;give_water&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;take_outside&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;play&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;dog_awake&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;dog_awake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
    &lt;span class="nf"&gt;chase_cat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;chew_toy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;beg_for_pets&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dog_energy&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# dog_energy low
&lt;/span&gt;    &lt;span class="nf"&gt;nap_time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# changes dog_awake to False
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;It’s doggy nap time!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Go Ahead! You can build it! &lt;code&gt;.lower()&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# coding .lower()
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  and maybe even &lt;code&gt;.title()&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# coding .title()
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  You got this! Build Scoring for a game
&lt;/h3&gt;

&lt;p&gt;You can use print statements or fake functions (like &lt;code&gt;throw()&lt;/code&gt; or &lt;code&gt;move_left()&lt;/code&gt;) to fill in the if-elif-else then blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# scoring for any game
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thank you to &lt;a class="mentioned-user" href="https://dev.to/yechielk"&gt;@yechielk&lt;/a&gt; for reviewing. If you like learning about how ethics and programming go together, check out their &lt;a href="https://torahandtech.dev/" rel="noopener noreferrer"&gt;book and newsletter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>python</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Python Switches to Match-Case</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Sun, 12 Dec 2021 17:52:43 +0000</pubDate>
      <link>https://dev.to/vickilanger/python-switches-to-match-case-4mmb</link>
      <guid>https://dev.to/vickilanger/python-switches-to-match-case-4mmb</guid>
      <description>&lt;p&gt;&lt;em&gt;If reading about code with &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;bar&lt;/code&gt;, and math examples is the bane of your existence, keep reading. Expect examples with sweaters and dogs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Jump to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Past&lt;/li&gt;
&lt;li&gt;
Present

&lt;ul&gt;
&lt;li&gt;Benefits&lt;/li&gt;
&lt;li&gt;Example 1&lt;/li&gt;
&lt;li&gt;Example 2&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Future&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Past &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Once upon a time, in 2006, a Python Enhancement Proposal(PEP) was introduced. &lt;a href="https://www.python.org/dev/peps/pep-3103/"&gt;PEP 3103&lt;/a&gt; detailed many different ways a switch statement could be implemented and why Python should have them. That's a long time ago though. Let's jump into the here and now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Present &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The possibility to use match-case statements in Python has not been around very long. The addition of match-case statements in based on &lt;a href="https://www.python.org/dev/peps/pep-0634/"&gt;PEP 634&lt;/a&gt;. They were introduced in October of 2021 with Python v3.10. If you are using Python v3.9 or older, you won’t be able to try these out. I don’t suspect you’ll be missing out on much as these are relatively new. By the time you need them, I’m sure you’ll pick them up quickly. Either way, keep reading just to get a quick introduction to the concept. If you skip reading this, you won’t miss anything other than some cute examples. I’d suggest at least checking those out.&lt;/p&gt;

&lt;p&gt;Worth noting, if you hear others talk about switch-case statements, match-case is pretty much the same thing.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt;
Match-case statements are incredibly similar to if-else statements. Seemingly, they can be used interchangeably. Match-case does have a few benefits though. Your computer can read and understand match-case statements quicker than if-else statements. On that note, it tends to be easier for you and other programmers to read and manage match-case statements.&lt;/p&gt;

&lt;p&gt;I think it’s time for an example. Is it time to play with your dog?&lt;br&gt;
&lt;a&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dog_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is your dog's name?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;dog_wants_to_play&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;  &lt;span class="c1"&gt;# they always want to play!
&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;dog_wants_to_play&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Go get it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dog_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Okay"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dog_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"maybe we'll play later"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait, but how would that look as an if-else statement?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dog_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is your dog's name?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;dog_wants_to_play&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;  &lt;span class="c1"&gt;# they still always want to play!
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;dog_wants_to_play&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Go get it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dog_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Okay"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dog_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"maybe we'll play later"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that doesn't seem very useful. When making a decision that only has two options, an if-else statement is actually shorter. That's okay because match-case statements really shine and show off their usefulness when we have more options.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comparison &lt;code&gt;if-else&lt;/code&gt; vs &lt;code&gt;match-case&lt;/code&gt; &lt;a&gt;&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;Are you cold? I'm cold. Let’s take a trip to the Sleevonista sweater factory. Sleevonista makes one-size-fits-all sweaters with different amounts of sleeves. Here's a long kinda unwieldy if-else example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give to spider, squid, or octopus"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give to butterfly, bumble bee, Octocat™"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give to 3 or 4 legged dog"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give sweater to human with 1 or 2 arms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give sweater to to your snake friend"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"sweater is broken, make another one"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's turn Sleevonista's into a match-case statment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many sleeves does the sweater have?"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give to spider, squid, or octopus"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give to butterfly, bumble bee, Octocat™"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give to 3 or 4 legged dog"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give sweater to human with 1 or 2 arms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"give sweater to to your snake friend"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# NOTE: unsure on the accuracy of this line's syntax
&lt;/span&gt;        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"sweater is broken, make another one"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"You made a sweater"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the wildcard &lt;code&gt;_&lt;/code&gt;. This will always be True and it considered irrefutable. You may only have one irrefutable case and it has to be the at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;As time goes by, I imagine match-case statements in python will catch on. Eventually, the'll be as commonplace as switch-case statements in languages like Ruby, Java, and so many other languages. If you'd like more read more on the motivation and rationale behind Python now having match-case statements, checkout &lt;a href="https://www.python.org/dev/peps/pep-0635/"&gt;PEP 635&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What other examples can you think of? Can you come up with some real life examples? Comment below with what you come up with.&lt;/p&gt;

</description>
      <category>python</category>
      <category>challenge</category>
    </item>
    <item>
      <title>If This... Then That</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Sun, 05 Dec 2021 14:15:57 +0000</pubDate>
      <link>https://dev.to/vickilanger/if-this-then-that-585</link>
      <guid>https://dev.to/vickilanger/if-this-then-that-585</guid>
      <description>&lt;p&gt;&lt;em&gt;If learning to code with math examples are the bane of your existence, keep reading. This series uses relatable examples like animals.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Jump To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Comparing &lt;/li&gt;
&lt;li&gt;On One Condition or More or Not&lt;/li&gt;
&lt;li&gt;Decision Making&lt;/li&gt;
&lt;li&gt;Practice Challenges&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let’s Compare &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Alligator Signs &amp;lt; &amp;amp; &amp;gt;: Which is which?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxcga53fzwveleez2iat.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxcga53fzwveleez2iat.png" alt="Alligator/crocodile siting at a desk with question marks next to &amp;lt; and &amp;gt; signs"&gt;&lt;/a&gt;&lt;br&gt;
In school, many of us were taught &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt; by imagining they were alligators and crocodiles, Pac-Man, or a crooked letter “L”. Basically, the big open side eats the bigger thing. If you’re like me, this was super confusing. The concept is great, but it made me focus too hard on knowing which item was greater than the other and less on how to read statements like &lt;code&gt;1 &amp;lt; 2&lt;/code&gt; and &lt;code&gt;4 &amp;gt; 3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reading these types of statements properly will be immensely helpful to you while coding. For starters, we code from left to right. As you’re reading, the side you get to first is the part you want to pay attention to. If the little pointy side is first, on the left, then that is a less than sign. If the big open mouth side is first, on the left, then it is a greater than sign. Here’s a quick example to help you practice reading them correctly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# common number of feet for each
&lt;/span&gt;&lt;span class="n"&gt;dog_feet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;person_feet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="n"&gt;dog_feet&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person_feet&lt;/span&gt;
&lt;span class="n"&gt;person_feet&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;dog_feet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also say something is &lt;code&gt;&amp;lt;=&lt;/code&gt; or &lt;code&gt;&amp;gt;=&lt;/code&gt;. If you were deciding whether or not it is freezing outside, you may say “if the temperature is &amp;lt;= 32°F or 0°C, then it is freezing”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;temp_f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="n"&gt;freezing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp_f&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  That's Not True
&lt;/h4&gt;

&lt;p&gt;Now that you can definitely read these less than and greater than signs, let’s talk about what we use them for. Remember the type of data we called &lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi#bool"&gt;“boolean”&lt;/a&gt;? In code, we use them to help us know if a statement is &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;. In the feet comparison example we just used, both statements are true. Though, this isn’t always the case in code. Sometimes statements are true and sometimes they are false. These are typically used in &lt;code&gt;if&lt;/code&gt; statements to help us make decisions. We’ll go over those shortly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# common number of feet for each
&lt;/span&gt;&lt;span class="n"&gt;dog_feet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;fish_feet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  &lt;span class="c1"&gt;# I hope
&lt;/span&gt;
&lt;span class="n"&gt;fish_feet&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dog_feet&lt;/span&gt;  &lt;span class="c1"&gt;# this is False
&lt;/span&gt;&lt;span class="n"&gt;dog_feet&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;fish_feet&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;  &lt;span class="c1"&gt;# this is also False
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Is it or is it not?
&lt;/h3&gt;

&lt;p&gt;A quick reminder: variables use one equals sign &lt;code&gt;=&lt;/code&gt; to &lt;a href="https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi#vars"&gt;assign the value&lt;/a&gt; on the right to the variable name on the left. That’s not its only job though, the &lt;code&gt;=&lt;/code&gt; is overloaded with work. It has lots of jobs in programming. Its first job is to assign values to variables. Its other jobs are to help us compare things, but it will look a little different. If we use two equals signs &lt;code&gt;==&lt;/code&gt; it means we are trying to compare whether or not the things on either side are of the same value. The side an item is on doesn’t matter. We just want to know if the items are the same integer, string, boolean, etc. I would read &lt;code&gt;thing_1 == thing_2&lt;/code&gt; as “thing_1 is the same value as thing_2”.&lt;/p&gt;

&lt;p&gt;That’s great, but what if we specifically want to know if something is not the same as something else? I’m so glad you asked, we have something for that too. Instead of two equals signs, we use &lt;code&gt;!=&lt;/code&gt;. In programming, almost always &lt;code&gt;!&lt;/code&gt; translates to &lt;code&gt;not&lt;/code&gt;. So, this time, we’d read &lt;code&gt;thing_1 != thing_2&lt;/code&gt; as “thing_1 is not the same value as thing_2”.&lt;/p&gt;

&lt;p&gt;Like &lt;code&gt;&amp;lt;&lt;/code&gt; or &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; are also generally used with &lt;code&gt;if&lt;/code&gt; statements. Really, any time we are comparing things, you’re likely to see some version of an &lt;code&gt;if&lt;/code&gt; statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# common number of lungs for each
&lt;/span&gt;&lt;span class="n"&gt;snail_lungs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;fish_lungs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;horse_lungs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;snails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="c1"&gt;# we have 2 snails
&lt;/span&gt;
&lt;span class="n"&gt;fish_lungs&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;snail_lungs&lt;/span&gt;  &lt;span class="c1"&gt;# this is False
&lt;/span&gt;&lt;span class="n"&gt;snail_lungs&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;fish_lungs&lt;/span&gt; &lt;span class="c1"&gt;# yep, still False
&lt;/span&gt;&lt;span class="n"&gt;snail_lungs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;horse_lungs&lt;/span&gt;  &lt;span class="c1"&gt;# finally, a True comparison
&lt;/span&gt;
&lt;span class="n"&gt;fish_lungs&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;snail_lungs&lt;/span&gt;  &lt;span class="c1"&gt;# this is True
&lt;/span&gt;&lt;span class="n"&gt;snail_lungs&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;fish_lungs&lt;/span&gt; &lt;span class="c1"&gt;# yep, still True
&lt;/span&gt;&lt;span class="n"&gt;snail_lungs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;horse_lungs&lt;/span&gt;  &lt;span class="c1"&gt;# this one is False
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokr9604w0i4b7ey097ik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokr9604w0i4b7ey097ik.png" alt="cheetah image == house cat image == dog"&gt;&lt;/a&gt;&lt;br&gt;
To test out whether a comparison is &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;, you can print your comparison. Did you know our pet cats aren’t the only ones that meow? Test it out with this example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;house_cat_sound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meow&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;snow_leopard_sound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meow&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;cheetah_sound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meow&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;house_cat_sound&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;snow_leopard_sound&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;cheetah_sound&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;house_cat_sound&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;snow_leopard_sound&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;dog_sound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;woof&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;house_cat_sound&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;snow_leopard_sound&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;cheetah_sound&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;dog_sound&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cheetah_sound&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;dog_sound&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  On One Condition or More or Not &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we know how to compare, let’s talk about Python’s logical operators. We use these operators, or words, to help us arrange things logically.&lt;/p&gt;

&lt;p&gt;Imagine you have a bunch of things to do today. On your to-do list, you have: do laundry, play games, clean the kitchen, and feed dogs. From your to-do list, some of these things must be done and some could wait until later. We can use keywords to explain which ones are necessary, which are maybe getting done, and which ones are not going to be done today.&lt;br&gt;
Here's our to-do list:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fin77091veecue5gezsri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fin77091veecue5gezsri.png" alt="A piece of paper that says "&gt;&lt;/a&gt;&lt;br&gt;
We only have enough energy to do three of the four things. We know we must feed the dogs. When we have to do something we use &lt;code&gt;and&lt;/code&gt;. This will make a program know this condition or item is required.&lt;/p&gt;

&lt;p&gt;When conditions are optional, we use &lt;code&gt;or&lt;/code&gt;. You realize the kitchen isn’t actually that messy and you still have enough clothes for tomorrow. Now that you know you don’t have to do both, you will have time to play games. Now, let’s put this into code.&lt;/p&gt;

&lt;p&gt;There is the option to do &lt;code&gt;kitchen or laundry&lt;/code&gt;, then we know we have to feed the dogs. So, we end up with &lt;code&gt;kitchen or laundry and feed_dogs&lt;/code&gt;. Wait, we need games too and only have energy for three things on our list! Today, we decide the kitchen will probably not get done.&lt;/p&gt;

&lt;p&gt;With both &lt;code&gt;and&lt;/code&gt; and &lt;code&gt;or&lt;/code&gt;, we are checking to see if things are &lt;code&gt;True&lt;/code&gt;. With &lt;code&gt;and&lt;/code&gt;, the condition  to the right of it must be &lt;code&gt;True&lt;/code&gt;. With &lt;code&gt;or&lt;/code&gt;, one or both of the conditions must be &lt;code&gt;True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, we have &lt;code&gt;not&lt;/code&gt;, which is generally all by itself. This will use a boolean value, like &lt;code&gt;True&lt;/code&gt;, and make it the opposite. Imagine you want to know if it is raining. If someone says it is &lt;code&gt;not raining&lt;/code&gt;, that would make &lt;code&gt;raining&lt;/code&gt;, &lt;code&gt;False&lt;/code&gt;. In our to-do list example, the kitchen needs to be cleaned and we have &lt;code&gt;kitchen = True&lt;/code&gt;. If we say, &lt;code&gt;not kitchen&lt;/code&gt;, that means we have decided not to clean the kitchen. Here’s what this to-do list could look like in code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# all tasks need to be done, so we start them as True
&lt;/span&gt;&lt;span class="err"&gt;​​&lt;/span&gt;&lt;span class="n"&gt;kitchen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;laundry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;games&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;feed_dogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="c1"&gt;# if we had energy for all tasks
&lt;/span&gt;&lt;span class="n"&gt;kitchen&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;laundry&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;games&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;feed_dogs&lt;/span&gt;

&lt;span class="c1"&gt;# only energy for three tasks
&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;kitchen&lt;/span&gt;  &lt;span class="c1"&gt;# guess we’ll do it tomorrow
&lt;/span&gt;&lt;span class="n"&gt;chores_done&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;laundry&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;games&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;feed_dogs&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chores_done&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how we have parentheses &lt;code&gt;()&lt;/code&gt;. Just like in math, there is an order of how things are done. In Python, &lt;code&gt;and&lt;/code&gt; will always happen first, unless there are parentheses. We need them to show we have energy for laundry or games, but we also have to feed the dogs. Without the parentheses, we could be saying we have energy for games and feeding dogs or we have energy for laundry.&lt;/p&gt;

&lt;p&gt;Wanna test this further? Try changing around the boolean values for the tasks.&lt;/p&gt;

&lt;p&gt;Similar to &lt;code&gt;&amp;lt;&lt;/code&gt; or &lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;and&lt;/code&gt;, and &lt;code&gt;not&lt;/code&gt; are also often used with &lt;code&gt;if&lt;/code&gt; statements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Controlling the Flow and Making Decisions &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Have you ever made a decision before? Maybe you’ve decided what to eat for dinner, what to wear today, or even what colors to mix to make another color. These are all things we can use code to help us with. The most basic way to make decisions is set up to be read like: “If something is True, then we will do this. If it isn’t True, we will do something else.”&lt;/p&gt;

&lt;h3&gt;
  
  
  If This
&lt;/h3&gt;

&lt;p&gt;First, let's talk about &lt;code&gt;if&lt;/code&gt; statements. I’ve mentioned them a few times and how we can use the comparison operators (&lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;) and logical operators (&lt;code&gt;or&lt;/code&gt;, &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt;) with them. &lt;code&gt;If&lt;/code&gt; statements/blocks only cover “If something is True, then we will do this”. Shall we jump into an example?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current_c_temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# about 60F
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chilly outside, wear warm clothes &amp;amp; limit time outside&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the first line of our code, the &lt;code&gt;if&lt;/code&gt; statement, is &lt;code&gt;True&lt;/code&gt; then we will do the code in the &lt;code&gt;if&lt;/code&gt; block. An &lt;code&gt;if&lt;/code&gt; block is defined by the lines underneath the &lt;code&gt;if&lt;/code&gt; line that are tabbed in. The block ends when a line is no longer tabbed in. Great, we know what to do if it’s cold outside, but what if it’s not?&lt;/p&gt;

&lt;h3&gt;
  
  
  If not, Something Else
&lt;/h3&gt;

&lt;p&gt;If your &lt;code&gt;if&lt;/code&gt; statement is &lt;code&gt;False&lt;/code&gt;, we can do something else. We can add an &lt;code&gt;else&lt;/code&gt; block. An &lt;code&gt;else&lt;/code&gt; block includes a line that says &lt;code&gt;else:&lt;/code&gt; and the tabbed in lines that happen if the &lt;code&gt;if&lt;/code&gt; statement was &lt;code&gt;False&lt;/code&gt;. With our temperature example, let’s add in an &lt;code&gt;else&lt;/code&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current_c_temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# about 60F
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chilly outside, wear warm clothes &amp;amp; limit time outside&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;have fun outside, it’s not too cold&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we were going to read this out loud, we’d say something like: “If the current celsius temperature is below 15 degrees, we should wear warm clothes and limit time outside. If the current celsius temperature is &lt;strong&gt;not&lt;/strong&gt; below 15 degrees, we shall do something else. We will leave our jackets inside and have fun outside.”&lt;/p&gt;

&lt;p&gt;Of course these aren’t the only possible temperatures, right? There’s more than just cold and not cold. For situations like this, we can have multiple test conditions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiple Conditions with Elif
&lt;/h3&gt;

&lt;p&gt;For multiple conditions, we have &lt;code&gt;elif&lt;/code&gt; blocks. These look exactly like &lt;code&gt;if&lt;/code&gt; blocks, but with an &lt;code&gt;el&lt;/code&gt; in front of it. They go in between if and else blocks. Time to adjust our example again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current_c_temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# about 60F
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chilly outside, wear warm clothes, limit time outside&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;current_c_temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;current_c_temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# between ~60F and ~82F
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;have fun outside, it’s not too cold or too hot&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Wear light clothes, avoid long time in sun, drink extra water&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that only one of the blocks is actually going to be used. This is the goal. We want to use if-elif-else blocks to help us make decisions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages4-g.ravelrycache.com%2Fuploads%2Fdoctorhectic%2F569858321%2F2321568580_92f9c1d4cc_b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages4-g.ravelrycache.com%2Fuploads%2Fdoctorhectic%2F569858321%2F2321568580_92f9c1d4cc_b.jpg" alt="knitted red octopus sitting on a laptop wearing a knitted yellow sweater"&gt;&lt;/a&gt;&lt;br&gt;
Temperatures are great and all, but it's chilly. Let’s take a trip to the Sleevonista™ sweater factory. Sleevonista™ makes one-size-fits-all sweaters with different amounts of sleeves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;give to spider, squid, or octopus&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;give to butterfly, bumble bee, grasshopper&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;give to 3 or 4 legged dog&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;give sweater to human with 1 or 2 arms&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;sweater_sleeves&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;give sweater to your snake friend&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sweater is broken, make another one&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Do you remember? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here's some practice challenges. Let’s practice what we’ve learned so far. Go ahead and comment on this post with your answers. Do you remember? If not, you can always go back to read sections again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Give an example of each
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;How you’d read it out loud&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Comparison Operators&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;(&lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logical Operator &lt;code&gt;and&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logical Operator &lt;code&gt;or&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logical Operator &lt;code&gt;not&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Are these &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;You are more than welcome to test these out. Don’t expect yourself to understand everything right away. Do test yourself first though.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;skyscraper_size &amp;lt; bicycle_size&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eat_food and drink_water&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;your_age == parent_age&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;num_dinosaurs_alive &amp;gt;= num_chickens_alive&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;not millionaire&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cheetah_top_speed &amp;lt;= sloth_top_speed&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;apple_weight != watermelon_weight&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;snowing or !snowing&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;dog_age_in_human_years * 7 &amp;gt; your_age&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Time to make your own decision!
&lt;/h3&gt;

&lt;p&gt;Don’t forget that you can and probably should start with &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970#pseudocode"&gt;pseudocode&lt;/a&gt;. &lt;br&gt;
&lt;em&gt;Some ideas&lt;/em&gt;: when to play with dog, what’s for dinner, what movie you want to watch next, water flowing through pipes, or anything else.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# if something is True, 
&lt;/span&gt;    &lt;span class="c1"&gt;# then we do this
# if not that, maybe this is True, if it is
&lt;/span&gt;   &lt;span class="c1"&gt;# then we do this
# if none of those, something else
&lt;/span&gt;   &lt;span class="c1"&gt;# then we do this
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thank you to &lt;a class="mentioned-user" href="https://dev.to/andyhaskell"&gt;@andyhaskell&lt;/a&gt; for reviewing and the very first owner of Sleevonista™ Original sweater.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>challenge</category>
      <category>codenewbie</category>
      <category>python</category>
    </item>
    <item>
      <title>Your First Line of Code</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Sun, 21 Nov 2021 17:24:46 +0000</pubDate>
      <link>https://dev.to/vickilanger/your-first-line-of-code-5ebi</link>
      <guid>https://dev.to/vickilanger/your-first-line-of-code-5ebi</guid>
      <description>&lt;p&gt;&lt;em&gt;If learning to code with math examples are the bane of your existence, keep reading. This series uses relatable examples like dogs and cats.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Jump To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your First Program&lt;/li&gt;
&lt;li&gt;Practice Challenges&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hello, World!
&lt;/h2&gt;

&lt;p&gt;When learning to code, you must start somewhere. You’re not going to jump in and already know how to do things. Some things will look like magic at first. As you go along you’ll learn more and more about how those magic things actually work.&lt;/p&gt;

&lt;p&gt;The first program most programmers start with is called "Hello, World". This program is the starting point because it shows some of the language’s &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970#syntax"&gt;syntax&lt;/a&gt; and it feels good when you can see the output of your work. This tradition has been around since 1974 when it was first introduced into a programming tutorial book.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your First Program! &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In whichever editor you choose (eg Python Tutor, Trinket, IDLE, etc), type in the code below and run the code. If you don’t know how to run the code, you can always refer back to the &lt;a href="https://dev.to/vickilanger/where-do-i-code-3cb2"&gt;&lt;em&gt;Where Do I Code&lt;/em&gt;&lt;/a&gt; post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Depending on your editor, your output will show a little differently, but it will still be displayed. If you got it to work, congratulations! You’ve built your first program!&lt;/p&gt;

&lt;p&gt;Try it again, but this time use your own words. Leave the quotes and put your own words inside them.&lt;/p&gt;
&lt;h3&gt;
  
  
  Um, It Didn’t Work. Now what do I do?
&lt;/h3&gt;

&lt;p&gt;If your code didn’t work, that is okay. This happens ALL the time. In &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970"&gt;&lt;em&gt;How Do I Code&lt;/em&gt;&lt;/a&gt;, we talked about bugs and debugging? You have a bug and you need to debug your program. Here are the steps we want to go through.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Look at the code you last wrote. It’s likely to be the culprit.&lt;/li&gt;
&lt;li&gt;Make sure the syntax is good.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We have yet to go over the &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970#syntax"&gt;syntax&lt;/a&gt; of anything in this program. So, here are some things to check. If you don’t have them, go ahead and fix your code. You can run your code after every change to see if it works.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;print&lt;/code&gt; should be lowercase&lt;/li&gt;
&lt;li&gt;There should be parentheses surrounding your words&lt;/li&gt;
&lt;li&gt;Your words and their punctuation should be surrounded by quotes (like this &lt;code&gt;"puppy"&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Some Magic with Print
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://dev.toTBD"&gt;&lt;em&gt;How Do I Code&lt;/em&gt;&lt;/a&gt;, we talked about documentation and the importance of reading it. I know it can be scary, but I promise it will help. Let’s take a look at what Python docs have for this &lt;code&gt;print()&lt;/code&gt;. You can go to the docs here: ​​&lt;a href="https://docs.python.org/3/library/functions.html#print" rel="noopener noreferrer"&gt;https://docs.python.org/3/library/functions.html#print&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;br&gt;
​​&lt;br&gt;
This is showing us the &lt;a href="https://dev.to/vickilanger/how-do-i-code-4970#syntax"&gt;syntax&lt;/a&gt; of a print statement and what arguments are required and allowed. Remember, arguments are the things that go inside the &lt;code&gt;()&lt;/code&gt; and are separated by commas. There are five arguments; We’ll go over the first three. Any arguments that have an &lt;code&gt;=&lt;/code&gt; are not required as they had defaults set to whatever is after the &lt;code&gt;=&lt;/code&gt;. Here are the three we’ll work with.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;objects&lt;/code&gt; refers to whatever you want to print and the &lt;code&gt;*&lt;/code&gt; just means you can put as many things, separated by commas, as you want.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sep=' '&lt;/code&gt; is saying that each of those things, or objects, will be separated by a single space, by default. If you were to give &lt;code&gt;sep=',  '&lt;/code&gt; your objects would be separated by &lt;code&gt;,&lt;/code&gt; a comma and a space.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;end='\n'&lt;/code&gt; says that at the end of whatever you are printing, it is giving a new line. It’s basically hitting the enter key after you print. You can change that if you want by giving something other than &lt;code&gt;\n&lt;/code&gt; for the end.
Sometimes it can be helpful to give a separator and/or a different end of the line. Here are a few examples. Try it out for yourself.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# print() separator example
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mouse&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dog&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# prints cat mouse dog
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mouse&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dog&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# prints cat, mouse, dog
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mouse&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dog&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;123&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# prints cat123mouse123dog
&lt;/span&gt;
&lt;span class="c1"&gt;# print() end example
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1st print&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# prints 1st print,
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2nd print&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Welcome to the world of programming. Now that you’ve done a couple lines of code, you are a programmer. As a programmer, we are always learning. So, try practicing with these challenges below. Then, you’re welcome to keep going and click the next post at the bottom.&lt;/p&gt;


&lt;h2&gt;
  
  
  Do you remember?&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here's some practice challenges. Let’s practice what we’ve learned so far. Go ahead and comment on this post with your answers. If you don't remember, no worries, you can always go back to read sections again.&lt;/p&gt;
&lt;h3&gt;
  
  
  Can You Fix What's Wrong with These?
&lt;/h3&gt;

&lt;p&gt;Some of these have more than one right answer. Believe in yourself and give it a try.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Print("Hi there")"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;print"(Bom Dia!, sep="... ")"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;print("​​Nǐ hǎo", sep" - ")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;print("¡Hola"!)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;print.("Assalamu Alaikum", end=" ")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Make some example print statements and give their output
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Print Statement&lt;/th&gt;
&lt;th&gt;What Would the Output look like&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Just words&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;With a different Separator&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;With a different End&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/vickilanger" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F169425%2F48b84fd1-2234-47cd-a498-7be383beb8bb.jpeg" alt="vickilanger"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/vickilanger/words-numbers-variables-oh-my-mmi" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Words, Numbers, &amp;amp; Variables, Oh My&lt;/h2&gt;
      &lt;h3&gt;Vicki Langer ・ Nov 17 '21&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#challenge&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#codenewbie&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#python&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>python</category>
      <category>codenewbie</category>
      <category>challenge</category>
    </item>
    <item>
      <title>8 Tools I Wish I Knew About When I started Coding</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Sun, 21 Nov 2021 17:23:23 +0000</pubDate>
      <link>https://dev.to/vickilanger/how-do-i-code-4970</link>
      <guid>https://dev.to/vickilanger/how-do-i-code-4970</guid>
      <description>&lt;p&gt;&lt;strong&gt;Jump To&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax&lt;/li&gt;
&lt;li&gt;
Reading Docs &lt;/li&gt;
&lt;li&gt;
Pseudocode &lt;/li&gt;
&lt;li&gt;
Commenting &lt;/li&gt;
&lt;li&gt;
I Want It That Way &lt;/li&gt;
&lt;li&gt;
Eek! Errors :( Tell Me Why &lt;/li&gt;
&lt;li&gt;Practice Challenges&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Coding can be as easy as typing exactly what you see in a book, video, or tutorial and hoping it works. This will work at first, but it’s better to have some tools to help you learn and really understand what you’re doing along the way. These tools will help you better understand what you’re doing and how things work. All of these tools are things professional programmers depend on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nsvv71tn3gcixf2ujjf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nsvv71tn3gcixf2ujjf.png" alt="miscellaneous garage tools labelled as syntax, docs, pseudocode, commenting, naming, debugging"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Syntax &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Whether you’re writing in English, Pashto, Hebrew, or a programming language they all require you to use combinations of characters, numbers, and symbols. These combinations of characters, numbers, and symbols mean something. When you were learning to read you were programming your brain to understand these combinations as different sounds. Then you used these sounds to make words. Once you could read words, you could read sentences. There are rules or syntax that tell us how sounds and words work together. Syntax tells us what the correct format is to write certain things.&lt;/p&gt;

&lt;p&gt;In programming, syntax is used to define the correct combinations of characters, numbers, and symbols to make the code work. The syntax is different for each programming language just like it is for written and spoken languages. For every new code thing you learn, you want to make sure you look at the syntax and refer back to it if you don’t remember. If you type the wrong syntax, the computer will not understand and it will give you a &lt;code&gt;SyntaxError&lt;/code&gt;. If you get a syntax error, look up the syntax to verify you have the right thing.&lt;/p&gt;

&lt;p&gt;When looking up the syntax the best option is to look at the documentation. What is given in a tutorial, video, or book is probably correct, but sometimes things change or there are typos. Documentation is the go-to source for all your syntax needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading Documentation and Searching the Web &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;As our go-to source of information, documentation or docs as most programmers call it, is incredibly important. You can go directly to the documentation website (docs.python.org), but sometimes the website isn’t the easiest to navigate when you don’t know all the terms that are on it. Personally, I choose to go to my search engine (e.g. DuckDuckGo, Bing, Google) and type in &lt;code&gt;python docs&lt;/code&gt; and the thing I want to look up. Most of the time, one of the first results is exactly what I need. Notice, I included the language I’m working with and the word &lt;code&gt;docs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reading documentation can feel daunting at first. Let’s look at an example and figure out what’s what. There are several things we need to look at.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Syntax - the name and required symbols to use, in this case &lt;code&gt;print()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Required things - anything inside the &lt;code&gt;()&lt;/code&gt; without an equals sign &lt;code&gt;=&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Things Not Required - anything inside the &lt;code&gt;()&lt;/code&gt; with an equals sign &lt;code&gt;=&lt;/code&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7jadf834fblv3nz60o9.png" alt=" raw `print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)` endraw  with a "&gt;
These things may look like gibberish, but I promise, no one expects you to understand what any of this means. In the documentation there is a description of each thing in the &lt;code&gt;()&lt;/code&gt; underneath this line of code.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Pseudocode &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;We all program every single day of our lives whether or not we realize it. When you get up in the morning, you plan out your day. This act of planning is creating a script or program for your day. This may not be in a computer programming language, but it is absolutely programming. It’s an informal list of steps or a to-do list. In coding, we actually do something similar to this. We call it pseudocode.&lt;/p&gt;

&lt;p&gt;Sounds goofy, right? Why are we learning something that basically means “kinda sorta code”? Believe it or not, this is an integral step. Pseudocode is basically a to-do list. We use informal plain language to describe what we are about to code. You may think of it as an outline, plan, or to-do list.&lt;/p&gt;

&lt;p&gt;Once you have a pseudocode outline of what you want to build, you can use the steps to help guide what you want to code. In &lt;a href="https://dev.to/vickilanger/what-is-programming-35kf"&gt;&lt;em&gt;What is Programming&lt;/em&gt;&lt;/a&gt;, there was an example about how to build a watch. That was pseudocoding. The steps were written with all the focus on how it should work and not on the programming syntax. Though, in real pseudocode, each line would be a comment instead of a bullet on a list.&lt;/p&gt;

&lt;p&gt;If I were going to pseudocode for the watch, it would look something like this. Do know that there is no right or wrong way to pseudocode. You may choose to write it differently than someone else. That’s okay. It’s just a guide.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Repeat steps forever and ever until end of time or battery dies
&lt;/span&gt;
&lt;span class="c1"&gt;# Every 1 second up to 59, add 1 to the seconds on screen then
# Add 1 to the minutes on the screen up to 59 then
# Add 1 to the hours on the screen up to 12
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commenting &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In the pseudocode watch example, every line starts with a &lt;code&gt;#&lt;/code&gt;.  Whenever you use a &lt;code&gt;#&lt;/code&gt; you’re saying the computer should ignore what comes after it. What comes after the &lt;code&gt;#&lt;/code&gt; is meant for humans. Typically, comments are on the line above your code or at the end of the line. It should be an explanation of the what and why of your code. Think of it as a reminder to a future you and an explanation to anyone else reading your code. Oftentimes, your pseudocode will be repurposed and used to comment your code.&lt;/p&gt;

&lt;p&gt;You can also use comments to leave yourself to-do things with pseudocode notes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;Henna&lt;/span&gt; &lt;span class="n"&gt;Wars&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# output title of book
# TODO: output author of book - Adiba Jaigirdar
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: comments are different in different languages. For example, JavaScript uses &lt;code&gt;//&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  I Want it That Way &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;One of the best and worst things in programming is the fact that we have to name things. Naming can be a lot of fun. Later on, you’ll see that I named something &lt;code&gt;cat_summoning_spell&lt;/code&gt;. I promised I giggled when I came up with that. As fun as it can be, naming can be hard too.&lt;/p&gt;

&lt;p&gt;Names have to be unique. They can’t be the same as anything else or your program will get confused. Imagine having a cat named “Chicken” and a pet chicken. That would quickly get confusing.&lt;/p&gt;

&lt;p&gt;Names should also be memorable and descriptive. Using &lt;code&gt;x&lt;/code&gt; or &lt;code&gt;foo&lt;/code&gt; doesn’t explain what something is. Instead, you could describe what the thing is. If you’re counting stars, you could use something like &lt;code&gt;star_count&lt;/code&gt;, &lt;code&gt;star_num&lt;/code&gt;, or &lt;code&gt;num_of_stars&lt;/code&gt;. Having descriptive variables will help you avoid errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Eek! I got an Error. What now? - Tell Me Why &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If your code didn’t work, that is okay. This happens ALL the time. You have a bug and you need to debug your program. Here are the steps we want to go through. We’ll go into each of them in detail shortly. While they are in order, there is nothing saying you have to do them in this order.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read the Error&lt;/li&gt;
&lt;li&gt;Find the Culprit

&lt;ul&gt;
&lt;li&gt;Make sure the syntax is good.&lt;/li&gt;
&lt;li&gt;Names match (eg variables, functions, classes, etc)&lt;/li&gt;
&lt;li&gt;Comment out code&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Ask for help

&lt;ul&gt;
&lt;li&gt;Rubber Duck&lt;/li&gt;
&lt;li&gt;Google it&lt;/li&gt;
&lt;li&gt;Actually ask someone&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Take a Break&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Understanding the Error Messages
&lt;/h4&gt;

&lt;p&gt;I know, errors are scary and look like you broke something. There’s no need to worry though, it’s trying to help you. Errors tell you where the error is and what the problem might be. Let’s look at an example and figure out what’s what. There are several things we need to look at.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Type of error&lt;/li&gt;
&lt;li&gt;Description of error&lt;/li&gt;
&lt;li&gt;Line number - which line the error is on
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzcfk0tdq002bukcuyxv7.png" alt=""&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Find the Culprit
&lt;/h4&gt;

&lt;p&gt;Now that the error message has led you in the right direction, let’s look where it said the problem is. When you’re first learning to code, your most common errors will be a &lt;code&gt;SyntaxError&lt;/code&gt; and a &lt;code&gt;NameError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You’ll get a &lt;code&gt;SyntaxError&lt;/code&gt; when your syntax is messed up. Verify you have it right. I promise, even if you think you have it right, verify anyway. If you’re not sure, you can always look at documentation. Oftentimes, we assume we typed something right and we made a tiny mistake.&lt;/p&gt;

&lt;p&gt;Speaking of tiny mistakes, we get &lt;code&gt;NameError&lt;/code&gt; when names don’t match. For example, if you have something called &lt;code&gt;dog_feet&lt;/code&gt; but you later tried to use &lt;code&gt;dog_paws&lt;/code&gt; or &lt;code&gt;dog_foot&lt;/code&gt; you’ll get this &lt;code&gt;NameError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you’re having trouble finding the error, you can do what we call “commenting out code”. This means you can put a &lt;code&gt;#&lt;/code&gt; in front of that line so the computer will ignore that line. You’ll do this with lines that work perfectly and you know aren’t the problem. This helps narrow down the offending or broken code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Ask For Help
&lt;/h4&gt;

&lt;p&gt;If the other steps didn’t help, try asking for help. There are lots of ways to do this. You can do what we call “rubber ducking” or “rubber duck debugging.” This just means that you are explaining your code and the problem (to the best of your ability) out loud to something like a rubber duck or maybe your cat. You can also do this by typing out your problem as if you were going to ask a question. Oftentimes, this will solve your problem because you’ll be reading off your code and realize what was wrong.&lt;/p&gt;

&lt;p&gt;If explaining your code to a rubber duck, your cat, or your programmer friend hasn’t worked, try googling the problem. Typically this would mean you want to search the language you’re working with and the error. You might search something like &lt;code&gt;python NameError: name 'cats' is not defined&lt;/code&gt;. Generally the results will lead you in the right direction. You may have to look at a few different results to get the answer you need.&lt;/p&gt;

&lt;h4&gt;
  
  
  Take a Break
&lt;/h4&gt;

&lt;p&gt;If all else fails, take a break. Yes, seriously. Get up, walk away from your code. Take a walk, get some water, go play fetch with your dog, anything. I know you’re thinking this won’t work, but try it anyway. When you go back to your code later the problem may be glaringly obvious. It also might not be, but you’ve cleared your mind and are in a better position to find the pesky code. The goal here is to not sit there getting frustrated for a long time. Learning to code should be fun. If you find yourself getting upset with yourself, take a break.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do you remember? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s practice what we’ve learned so far. Go ahead and comment on this post with your answers. If you don't remember, no worries, you can always go back to read sections again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Write a Pseudocode example or three
&lt;/h3&gt;

&lt;p&gt;Try writing out the steps on how to do or build a real-life thing. Ideas: make a sandwich, use a TV, ride a bike, use a keyboard, or how water flows through kitchen sink plumbing&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pseudocode Examples&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;first example&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;another example&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;and maybe another?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>python</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Words, Numbers, &amp; Variables, Oh My</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Wed, 17 Nov 2021 18:41:31 +0000</pubDate>
      <link>https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi</link>
      <guid>https://dev.to/vickilanger/words-numbers-variables-oh-my-mmi</guid>
      <description>&lt;p&gt;&lt;em&gt;If coding tutorials with math examples are the bane of your existence, keep reading. This series uses relatable examples like dogs and cats.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Jump To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Words&lt;/li&gt;
&lt;li&gt;Numbers&lt;/li&gt;
&lt;li&gt;True or False&lt;/li&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Practice Challenges&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Programming’s Building Blocks - Data Types
&lt;/h2&gt;

&lt;p&gt;Think about the world around you. There are lots of different types of things, right? We can take all of those things and break them down into different types. For everything we see, we’ll call them different pieces of data or information. Each piece of data can be broken down into different types. These different types are the building blocks of programming. We’ll go into more detail on all of these, but for the most part, we have words, numbers, and true or false things.&lt;/p&gt;

&lt;p&gt;Look around you and take in your surroundings. We’re going to use them to make these data types. I’ll give examples with my surroundings, but please do use your own.&lt;/p&gt;

&lt;p&gt;For me, my surroundings have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a bookshelf with 23 books on it&lt;/li&gt;
&lt;li&gt;a half-full (or half-empty?) water bottle&lt;/li&gt;
&lt;li&gt;a dog bed with 2 cats sleeping on it&lt;/li&gt;
&lt;li&gt;a keyboard with 68 keys on it&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Strings &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The first type of data we’ll use is called a string. A string is a bunch of characters (eg. letters, numbers, symbols) surrounded by quotes. Strings can be a single letter, a word, a sentence, or even a whole book.&lt;/p&gt;

&lt;p&gt;Strings can use &lt;code&gt;""&lt;/code&gt; but they can also use single quotes, an apostrophe, &lt;code&gt;''&lt;/code&gt;. They must be in pairs though. If the quotes don’t match on both ends of a string, like this &lt;code&gt;’puppies”&lt;/code&gt;, it won’t  work.&lt;/p&gt;

&lt;p&gt;From my surroundings, I could have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Felix Ever After"
'They Both Die At The End'
"The Dangerous Art of Blending In"
"keyboard"
"Remmy and Beans are the 1 cats on the dog’s bed"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want your string to show on multiple lines, you can surround it with three pairs of quotes. Here’s an example of a multi-line string with a dog haiku.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""How do I love thee?
The ways are numberless as
My hairs on the rug.
-Author unknown
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Useful Built-in Functions for Strings
&lt;/h4&gt;

&lt;p&gt;Functions are actions you can use with your data. Python has a bunch that are already pre-built and ready for use. In order to use them, we first need to know the syntax, &lt;code&gt;functionname(“your string”)&lt;/code&gt;. Some helpful built-in functions for strings are &lt;code&gt;len()&lt;/code&gt;, &lt;code&gt;min()&lt;/code&gt;, and &lt;code&gt;max()&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;len()&lt;/code&gt; - returns the length&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;min()&lt;/code&gt; - returns the smallest value; “A” being the smallest&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;max()&lt;/code&gt; - returns the biggest value; “z” being the biggest; capitals being smaller than lowercase&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;chr()&lt;/code&gt; - returns the character associated with a given Unicode number, “chr” is short for character&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ord()&lt;/code&gt; - returns the Unicode number associated with a given character&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some examples. Try printing them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Kitties&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Kitties&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Kitties&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;86&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;V&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may not use them often, but with &lt;code&gt;chr()&lt;/code&gt; and &lt;code&gt;ord()&lt;/code&gt; is it helpful to know that each character is assigned and associated with a unicode code number. You can use &lt;code&gt;ord()&lt;/code&gt; to find out what that number is or you can look it up at &lt;a href="https://www.lookuptables.com/text/ascii-table" rel="noopener noreferrer"&gt;https://www.lookuptables.com/text/ascii-table&lt;/a&gt;. You’ll find that lowercase letters range from 97 to 122 and uppercase numbers range from 65 to 90. With that known, 97 &lt;code&gt;a&lt;/code&gt; is the lowercase version of 65 &lt;code&gt;A&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F97b0cxqvsccwj33zjvwh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F97b0cxqvsccwj33zjvwh.png" alt="a line showing uppercase A 65 to uppercase Z 90 and lowercase a 97 to lowercase z 122"&gt;&lt;/a&gt;&lt;br&gt;
Note, we are about to talk about the &lt;code&gt;.upper()&lt;/code&gt; method. Later on, we’ll learn how to code that using &lt;code&gt;chr()&lt;/code&gt; and &lt;code&gt;ord()&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Some Methods You Can Use with Strings
&lt;/h4&gt;

&lt;p&gt;Methods are special functions available based on an object’s type. We just learned that strings are a type. Let’s go over some methods we can use on strings. First, we should talk about how to use them or the syntax. String methods will look like &lt;code&gt;”your string”.methodname()&lt;/code&gt;. Sometimes there will be something in the parentheses, but not always.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;”your string”.upper()&lt;/code&gt; - returns string all uppercase&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;”your string”.title()&lt;/code&gt; - returns string with first letter of each word uppercase&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;”your string”.split()&lt;/code&gt; - returns your string cut up at it’s spaces and put into a list
Here are some examples. Try printing them.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Chickens slipping on a fondue fountain&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Llamas melting on a math recipe&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Snakes jumping on a potato pie&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt;
By the way, you can use multiple methods together. We call it method chaining. In order to chain methods, you put one method first, then the next one. They will still be separated by a &lt;code&gt;.&lt;/code&gt;. The methods will be applied in the order they are given. The below example will take the string and make each word start with an uppercase letter, then make all of the letters uppercase, lastly, it’ll cut the words apart and put them into a list. We’ll talk about lists later, don’t worry about them yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Llamas melting on a math recipe&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, this is a goofy example. I can’t actually think of a time it would make sense to chain &lt;code&gt;.title()&lt;/code&gt; and &lt;code&gt;.upper()&lt;/code&gt;, but it is possible. &lt;/p&gt;

&lt;h3&gt;
  
  
  Numbers &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The next type of data we’ll use is not called numbers. Instead, numbers are broken down into two different types. We have whole numbers and decimal numbers.&lt;/p&gt;

&lt;p&gt;Numbers do not need and should not have any quotes around them unless they are part of a string. Being part of a string would make them a string and not a type of number.&lt;/p&gt;

&lt;h4&gt;
  
  
  Integers
&lt;/h4&gt;

&lt;p&gt;Just like in math class, integers are whole numbers. Integers are never decimals or fractions. They are whole things. For example, you wouldn’t have 1.7 airplanes or 2.3 dogs. For things like this, you want to use the integer data type.&lt;/p&gt;

&lt;p&gt;From my surroundings, I could have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="c1"&gt;# books
&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="c1"&gt;# cats
&lt;/span&gt;&lt;span class="mi"&gt;68&lt;/span&gt; &lt;span class="c1"&gt;# keys on the keyboard
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: unlike real life, we don’t include commas in our numbers. If you have &lt;code&gt;1,000,000&lt;/code&gt; it would just be &lt;code&gt;1000000&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Useful Built-in Functions for Integers
&lt;/h5&gt;

&lt;p&gt;We have built-in functions for whole numbers too!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pow()&lt;/code&gt; - returns 1st number to the power of the second number, exponents&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;abs()&lt;/code&gt; - returns the absolute value or positive of a negative number
Here are some examples. Try printing them.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 2 * 2 * 2
&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# |3|
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
​​&lt;/p&gt;
&lt;h4&gt;
  
  
  Floats
&lt;/h4&gt;

&lt;p&gt;Similar to integers, but not the same, we have a type of data called floats. Floats are also called floating-point numbers. Floats are numbers with decimals. Floats can also be whole numbers, but typically only when you may need to count the portion of a thing.&lt;/p&gt;

&lt;p&gt;From my surroundings, I could have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, I only have the contents of my water bottle. From my surroundings, unless they’re broken, I can’t very well have a decimal number of books, cats, or keyboards.&lt;/p&gt;

&lt;h5&gt;
  
  
  Useful Built-in Functions for Floats
&lt;/h5&gt;

&lt;p&gt;I’m sure it comes as no surprise that floats have some built-in functions.&lt;br&gt;
Here are some examples. Try printing them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pow()&lt;/code&gt; - returns 1st number to the power of the second number, exponents&lt;/li&gt;
&lt;li&gt;`abs()’ - returns the absolute value or positive of a negative number&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;round()&lt;/code&gt; - returns a rounded decimal
Here are some examples. Try printing them.
&lt;code&gt;&lt;/code&gt;&lt;code&gt;python
pow(4.1, 2)
abs(-3.234)
round(3.65)
round(1.29)
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  You’re yes then you’re no - Booleans &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The last type of data we are going to cover is boolean. Like numbers, booleans do not need and should not have any quotes. They must start with a capital letter. Your only two options are the keywords &lt;code&gt;True&lt;/code&gt; and &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Booleans use &lt;code&gt;True&lt;/code&gt; and &lt;code&gt;False&lt;/code&gt; but they can be used as stand-ins for yes/no and on/off. If you choose to think of booleans as, yes/no or on/off, use &lt;code&gt;True&lt;/code&gt; for “yes” &amp;amp; “on” then use &lt;code&gt;False&lt;/code&gt; for “no” &amp;amp; “off”.&lt;/p&gt;

&lt;p&gt;From my surroundings, I could have:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;python&lt;br&gt;
True  # Remmy is sleeping&lt;br&gt;
False  # Beans is sleeping&lt;br&gt;
False  # Water bottle is full&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Your Data Dry with Variables &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we know the different types of data, let’s find a way to use each piece of data without having to type it over and over again. In programming, this concept of not retyping things is called Don’t Repeat Yourself(DRY). Variables help us keep code dry by holding data for us.&lt;/p&gt;

&lt;p&gt;Writing variables is incredibly similar to math class where you may have had &lt;code&gt;x = 5&lt;/code&gt; to mean there are 5 watermelons. The biggest and best difference is that we don’t typically use &lt;code&gt;x&lt;/code&gt;. Instead, we give descriptive names that help us understand what data we are working with. Instead of a letter variable, we can actually say what the variable stands for. Instead of &lt;code&gt;x = 5&lt;/code&gt; we could have &lt;code&gt;watermelon_count = 5&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Picking out a Name
&lt;/h3&gt;

&lt;p&gt;There are some rules with naming that have to be followed or your code won’t work as expected. Then there are some suggestions that you may or may not find helpful.&lt;/p&gt;

&lt;p&gt;Here are the requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Must start with a letter or &lt;code&gt;_&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Not allowed to use keywords (words set aside for different processes)&lt;/li&gt;
&lt;li&gt;Use lowercase letters and numbers&lt;/li&gt;
&lt;li&gt;No spaces, use &lt;code&gt;_&lt;/code&gt; instead&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some suggestions to make your life easier:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make the names descriptive&lt;/li&gt;
&lt;li&gt;Include the data type or structure&lt;/li&gt;
&lt;li&gt;Avoid single letter and atypically shortened names&lt;/li&gt;
&lt;li&gt;Variables are typically nouns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From my surroundings, I could have:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;python&lt;br&gt;
books_count_int = 23&lt;br&gt;
cat_one_name = "Remmy"&lt;br&gt;
cat_two_name = "Beans"&lt;br&gt;
water_level = 0.5&lt;br&gt;
keys_count_int = 68&lt;br&gt;
cat_one_sleeping = True&lt;br&gt;
cat_two_sleeping = False&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Did you notice that with the variable names, I didn’t have to include comments and you understood what each of those numbers meant? That’s why descriptive names are important. Had I called something &lt;code&gt;x&lt;/code&gt;, you wouldn’t have known which thing I was referring to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assignment
&lt;/h2&gt;

&lt;p&gt;Did you notice above where we used &lt;code&gt;=&lt;/code&gt; for our variables? We call the &lt;code&gt;=&lt;/code&gt; an assignment operator. I know it’s an equals sign, but I find it helpful to read it as “is”. In &lt;code&gt;cat_one_name = "Remmy"&lt;/code&gt;, I would read this out loud as “cat one name is Remmy”.&lt;br&gt;
Whatever is on the left of the &lt;code&gt;=&lt;/code&gt; is the variable name. The data on the right side is the value being assigned to the variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  More Dry with Built-ins and Methods
&lt;/h3&gt;

&lt;p&gt;Remember earlier where we printed the outcome of those built-in functions and methods? Let’s find a better way to get data from those. Before we do that, can we adjust each example line to use a variable?&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;python&lt;br&gt;
cat_str = “Kitties”&lt;br&gt;
len(cat_str)&lt;br&gt;
min(cat_str)&lt;br&gt;
max(cat_str)&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
Instead of printing each line, we can make them into variables. We call this “saving into a variable”. When you use, or run, a function or method in return it gives you some data. Usually, we will want to save that data to use later.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`python&lt;br&gt;
cat_str = "kitties jumping on a trampoline"&lt;br&gt;
cat_str_len = len(cat_str)&lt;br&gt;
cat_str_min = min(cat_str)&lt;br&gt;
cat_str_max = max(cat_str)&lt;br&gt;
heading = cat_str.title()&lt;/p&gt;

&lt;p&gt;print(heading)&lt;br&gt;
print(cat_str, "is", cat_str_len, "characters long")&lt;br&gt;
print(cat_str, "biggest letter:", cat_str_max, "smallest letter:", cat_str_min)&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this example, we could have easily counted how long the string was, but not everything will be that short. We were able to save the length of the string into a variable and use it later. This will become even more helpful as we learn more things.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Teensy Tiny Bit of Math
&lt;/h2&gt;

&lt;p&gt;I know, I know. I said there wouldn’t be a lot of math and it feels like everything has been about math. Whether we like it or not, a lot of the cool things we can do are based on some math concepts. For example, you can add and multiply words. Adding words is called concatenation but if you prefer, you can call it “smashing multiple strings together”.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;python&lt;br&gt;
short_greeting = "hey"&lt;br&gt;
long_greeting = short_greeting * 3&lt;br&gt;
different_greeting = short_greeting + "you"&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you put this code into Python Tutor, you’ll get the below. On the right, it will show you your variables and what values they hold.&lt;/p&gt;

&lt;p&gt;Notice that you can mix variables and data when using these math operators.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6cl705k3x5xpp0n2k3g7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6cl705k3x5xpp0n2k3g7.png" alt="Screenshot of Python tutor:  code:&amp;lt;br&amp;gt;
short_greeting = “hey”&amp;lt;br&amp;gt;
long_greeting = short_greeting * 3&amp;lt;br&amp;gt;
different_greeting = short_greeting + “you”&amp;lt;br&amp;gt;
 then it shows a chart to the right Frames&amp;lt;br&amp;gt;
Global frame&amp;lt;br&amp;gt;
short_greeting  "&gt;&lt;/a&gt;
long_greeting   "heyheyhey"&lt;br&gt;
different_greeting  "heyyou"&lt;br&gt;
"/&amp;gt;&lt;/p&gt;

&lt;p&gt;By the way, we also have addition &lt;code&gt;+&lt;/code&gt;, subtraction &lt;code&gt;-&lt;/code&gt;, multiplication &lt;code&gt;*&lt;/code&gt;, and division &lt;code&gt;/&lt;/code&gt;. These all work exactly as you would expect. They follow the same order of operations (eg PEMDAS or BODMAS) that you learned in math class. You may also choose to put parentheses &lt;code&gt;()&lt;/code&gt; around things you would like done first.&lt;/p&gt;

&lt;p&gt;There is another math operator &lt;code&gt;%&lt;/code&gt;, called modulus. It looks like and is a percent sign. However, it does something very different. &lt;code&gt;%&lt;/code&gt; is used like &lt;code&gt;/&lt;/code&gt; but it gives the remainder instead.&lt;/p&gt;

&lt;p&gt;Let’s use some variables and do a little math. We have some fruits and we want to share them with a group of people. If you divide them, you’ll find you would have to cut fruits in order to split them evenly. Instead, we can use &lt;code&gt;%&lt;/code&gt; or modulus to find out how many fruits are remaining. You can choose what to do with the remaining fruits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;python&lt;br&gt;
kiwis = 10&lt;br&gt;
apples = 7&lt;br&gt;
total_fruits = kiwis + apples&lt;br&gt;
people = 6&lt;br&gt;
fruits_per_person = total_fruits / people&lt;br&gt;
fruits_left_over = total_fruits % people&lt;br&gt;
print(fruits_left_over)&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you run this code in Python Tutor, it will look like this. On the right, it has an output box where all of your &lt;code&gt;print()&lt;/code&gt; statements show up. Under that it says “Frames”, that’s where it will show you your variables and what values they hold.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkg5kd5ucoakfgyexk6cg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkg5kd5ucoakfgyexk6cg.png" alt="Screenshot of Python tutor: code:&amp;lt;br&amp;gt;
kiwis = 10&amp;lt;br&amp;gt;
apples = 7&amp;lt;br&amp;gt;
total_fruits = kiwis + apples&amp;lt;br&amp;gt;
people = 6&amp;lt;br&amp;gt;
fruits_per_person = total_fruits / people  &amp;lt;br&amp;gt;
fruits_left_over = total_fruits % people&amp;lt;br&amp;gt;
print(fruits_left_over)&amp;lt;br&amp;gt;
 then it shows a chart to the right Frames&amp;lt;br&amp;gt;
Global frame&amp;lt;br&amp;gt;
kiwis   10&amp;lt;br&amp;gt;
apples  7&amp;lt;br&amp;gt;
total_fruits    17&amp;lt;br&amp;gt;
people  6&amp;lt;br&amp;gt;
fruits_per_person   2.8333&amp;lt;br&amp;gt;
fruits_left_over    5&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Do you remember? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here's some practice challenges. Let’s practice what we’ve learned so far. Go ahead and comment on this post with your answers. Do you remember? If not, you can always go back to read sections again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Match data with their data types
&lt;/h3&gt;

&lt;p&gt;Match each block on the left with its data type on the right. Each data type block should be used only twice.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc9buaexv5ol1n7f59xri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc9buaexv5ol1n7f59xri.png" alt="On the left, there are lego building blocks with different data type examples on them. On the left, there are lego building blocks with the data types on on them. The left has 3.14&amp;lt;br&amp;gt;
True&amp;lt;br&amp;gt;
92802834&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;
False&lt;br&gt;
"It’s True"&lt;br&gt;
185&lt;br&gt;
4591.28701&lt;br&gt;
The right has: Boolean, Float, String, Integer"/&amp;gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Give an example or three of each Type of Data
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Example 1&lt;/th&gt;
&lt;th&gt;Example 2&lt;/th&gt;
&lt;th&gt;Example 3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Integer&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Float&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Can You Fix What’s Wrong with These?
&lt;/h3&gt;

&lt;p&gt;Some of these have more than one right answer. Believe in yourself and give it a try.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'234 Puppies in 3 bathtubs"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;45,345.012&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;291’345’710.5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;27,345,192&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;90.0000° N, 135.0000° W&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;"4,823 bunnies frolicking in a field'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Off&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Make some Variables with each Type of Data
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Example 1&lt;/th&gt;
&lt;th&gt;Example 2&lt;/th&gt;
&lt;th&gt;Example 3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Integer&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Float&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  How would you read these out loud?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Examples&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;book_name = "The Meet Cute Diary"&lt;/code&gt; &lt;code&gt;print(book_name)&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cat_summoning_spell = "Here, " + ("Kitty " * 3)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;people = 7&lt;/code&gt; &lt;code&gt;treasure_chest_loot = 1000000&lt;/code&gt; &lt;code&gt;gold_coins_leftover = treasure_chest_loot % people&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>beginners</category>
      <category>challenge</category>
      <category>codenewbie</category>
      <category>python</category>
    </item>
    <item>
      <title>Why should I code?</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Mon, 15 Nov 2021 18:41:13 +0000</pubDate>
      <link>https://dev.to/vickilanger/why-should-i-code-1j7g</link>
      <guid>https://dev.to/vickilanger/why-should-i-code-1j7g</guid>
      <description>&lt;h2&gt;
  
  
  You call the shots!
&lt;/h2&gt;

&lt;p&gt;With code, you get to do whatever you want. Obviously, there are limitations. We should do things that make the world a better place, not worse. The sky is the limit and actually, that’s not really true either. You’re really just limited by your own creativity.&lt;/p&gt;

&lt;p&gt;Those limitations aside, you can build whatever you want. If you want to build a car that transforms into a tiger, you can. If you want to build an app that helps people without homes have access to free resources, you can do that. If you want to program a robot to throw a ball for your dog, you can.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fun of a challenge
&lt;/h2&gt;

&lt;p&gt;What’s the last thing you learned how to do? It was probably hard at first and then something clicked. Do you remember that awesome “aha, it makes sense” feeling? I promise you will get lots of that when learning to code. Of course, at times, that means it’s going to be hard. That “aha” feeling makes it all worth it. That feeling of accomplishment feels good.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Python and not [insert other programming language]?
&lt;/h2&gt;

&lt;p&gt;There are hundreds of programming languages. You could choose any one of them and be able to learn the same concepts and probably build all the same projects. Each language is typically built for a purpose, but that doesn’t mean it can’t do other things. Sometimes that purpose is just for fun and sometimes it’s to launch a rocket.&lt;/p&gt;

&lt;p&gt;In Python’s case, Python was written to make coding easier to read. This is why many programmers suggest learning to code with Python. You’ll also find that Ruby, JavaScript, and Java are often suggested for learning. There really is no right answer. In my experience, I find both Python and Ruby to be the easiest to read and write. Once you understand a few terms, they kinda read like English.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Where do I code?</title>
      <dc:creator>Vicki Langer</dc:creator>
      <pubDate>Mon, 15 Nov 2021 17:02:49 +0000</pubDate>
      <link>https://dev.to/vickilanger/where-do-i-code-3cb2</link>
      <guid>https://dev.to/vickilanger/where-do-i-code-3cb2</guid>
      <description>&lt;p&gt;Don’t I have to use [insert fancy computer] to code? No way! You can use any computer, tablet, or smartphone, it doesn’t even have to be connected to the internet. Though, some of the best resources are on the internet, for free.&lt;/p&gt;

&lt;p&gt;Fun fact: if you have one, you can even code with a graphing calculator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, Cool, but Where on my computer can I code?
&lt;/h2&gt;

&lt;p&gt;This is a hard question to answer because there are tons of places you can code. Let’s talk about a few different ones.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Free&lt;/th&gt;
&lt;th&gt;Easy to Use&lt;/th&gt;
&lt;th&gt;Visualize&lt;/th&gt;
&lt;th&gt;Can save your work&lt;/th&gt;
&lt;th&gt;Online&lt;/th&gt;
&lt;th&gt;Requires download&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;IDLE&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PythonTutor.com&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Trinket.io&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  IDLE
&lt;/h3&gt;

&lt;p&gt;This is an editor that comes with Python when you download it. (we’ll talk about downloading in a bit). It pretty much looks like a blank document that you can type in. You can type your code in, hit enter, and it will run your code. It looks like this. See the &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;? That’s telling you where you can type. For now, you can ignore the first 3 lines of what probably looks like gibberish.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CxeX2Ura--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2ku9sn69guiw0mcocz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CxeX2Ura--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2ku9sn69guiw0mcocz1.png" alt='Screenshot of Python 3.7.3 Shell. It shows 3 lines of text at the top, then a mostly blank line with "&amp;gt;&amp;gt;&amp;gt;" at the beginning' width="533" height="103"&gt;&lt;/a&gt;&lt;br&gt;
Note: IDLE does require that you download Python, which will require some space on your computer. We’ll cover how to install before we start coding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python Tutor
&lt;/h3&gt;

&lt;p&gt;Python Tutor is a free website you can use without logging in. It runs and helps visualize code. As you learn more things, I’ll explain what they should look like in Python Tutor. Personally, my vote is for everyone to start using this or something similar. For now, here is what Python tutor looks like when you go to &lt;a href="https://pythontutor.com/visualize.html#mode=edit"&gt;Python Tutor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You don’t have to adjust any of the drop-down menus, the defaults are perfect. You can type where it says &lt;code&gt;1&lt;/code&gt;. This just means you are on line 1 of the code. As you type more, it will number each line of code.&lt;/p&gt;

&lt;p&gt;There are two ways to use Python Tutor. With the first option, you may type all of your code, then click &lt;code&gt;Visualize Execution&lt;/code&gt; which allows you to click the &lt;code&gt;next&lt;/code&gt; button to see what happens at individual steps of your code.&lt;/p&gt;

&lt;p&gt;The other option is to click &lt;code&gt;Live Programming Mode&lt;/code&gt; or go to &lt;a href="https://pythontutor.com/live.html#mode=edit"&gt;Python Tutor Live&lt;/a&gt;. In this mode, your code will run as you type. I find this helpful as it immediately shows you what each step is doing.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q3G5cRhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wv8ialaurx1l3yqmfle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q3G5cRhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wv8ialaurx1l3yqmfle.png" alt='screenshot of Python Tutor showing the dropdown with the python version, the text box to write in, and the buttons "Visualize Execution" and "Live Programming Mode"' width="630" height="400"&gt;&lt;/a&gt;&lt;br&gt;
Most of the work you do, while learning, will run perfectly on Python Tutor. Though, there are a few projects that will work better with Trinket.io.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trinket.io
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://Trinket.io"&gt;Trinket.io&lt;/a&gt; is similar to Python Tutor in that it’s free and requires no downloads. It allows us to play with a few modules (already built code) that Python Tutor doesn’t support. You can choose to use Trinket for your projects if you want. Trinket does allow but doesn’t require you, to create an account that will save all of the code you build. If you choose not to create an account, you can use the editor on the Trinket.io webpage. The editor looks like the screenshot below.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YIlVq_8Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m84d1j30gnm6dqwjsp4d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YIlVq_8Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m84d1j30gnm6dqwjsp4d.png" alt="screenshot of Trinket.io editor. Editor shows a Turtle program that draws the trinket.io logo" width="880" height="414"&gt;&lt;/a&gt;&lt;br&gt;
To use the trinket editor, select and clear all of the code on the left. Then you can type in that area. Once you want to run, make your code do it’s thing, your code, click on the play symbol (▶). Once you’ve clicked ▶, the result of your code will show on the right.&lt;/p&gt;

&lt;p&gt;We’ll use Trinket later in the Modules section to play with emojis, date and time, turtle drawing, graphs and charts, and Wikipedia.&lt;/p&gt;

&lt;h3&gt;
  
  
  What if I already have a code editor or want one?
&lt;/h3&gt;

&lt;p&gt;That's great. If you know how, go ahead and use it. Python files end with &lt;code&gt;.py&lt;/code&gt;.  If you don’t know how, I highly suggest using one of the above options. I find it’s easiest to learn just one thing at a time. Learning code and how to use the editor may become a bit stressful and overwhelming.&lt;/p&gt;

&lt;p&gt;If you don't have an editor on your computer and want one, you may choose to install one like Atom from &lt;a href="https://atom.io/"&gt;https://atom.io/&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Either way, most examples will be explained using Python Tutor.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>codenewbie</category>
      <category>python</category>
    </item>
  </channel>
</rss>
