{"id":15009368,"url":"https://github.com/loveneeshdhir/python-for-beginners","last_synced_at":"2026-01-27T12:03:30.396Z","repository":{"id":91996831,"uuid":"252817390","full_name":"loveneeshdhir/Python-for-beginners","owner":"loveneeshdhir","description":null,"archived":false,"fork":false,"pushed_at":"2020-04-03T20:23:47.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T07:42:16.554Z","etag":null,"topics":["learning-python","programming-challenge","programming-languages","python","python-3","python-3-6","python-programming","python-tips","python3"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loveneeshdhir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-03T19:07:13.000Z","updated_at":"2021-01-02T11:51:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"38dec592-310b-460d-bb17-d0590797458a","html_url":"https://github.com/loveneeshdhir/Python-for-beginners","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"60b42170451aaafe23f230a7eff3aec1d8b1e336"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveneeshdhir%2FPython-for-beginners","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveneeshdhir%2FPython-for-beginners/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveneeshdhir%2FPython-for-beginners/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveneeshdhir%2FPython-for-beginners/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loveneeshdhir","download_url":"https://codeload.github.com/loveneeshdhir/Python-for-beginners/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243234043,"owners_count":20258383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["learning-python","programming-challenge","programming-languages","python","python-3","python-3-6","python-programming","python-tips","python3"],"created_at":"2024-09-24T19:24:45.877Z","updated_at":"2026-01-27T12:03:25.356Z","avatar_url":"https://github.com/loveneeshdhir.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Programming For Beginners\n\nWelcome to this repository on **\"Learning Python In 100 Steps\"**.\n\nI am **Loveneesh Dhir**, and I have two years of programming experience in Python.\n\n\nWhether we talk about big data, data analytics, or about doing simple things like scraping content from the web, Python is an awesome language for all that. Learning Python can be an awesome experience.\n\nIn this repo, you will learn to write **structural** and **object** **oriented** code with Python. You'll learn a lot of important Python concepts, including **types**, **modules**, **collections** (or **data** **structures**), **exceptions**, and a wide variety of other stuff. You will be exposed to a lot of examples, exercises and tips. We will take up a lot of examples, and try and see how to write code for those in Python.\n\nWe would be using **Python 3**, with **PyCharm** as the IDE.\n\n## Table of Contents\n* [Chapter 01 - Getting Ready with Python](#chapter-01---getting-ready-with-python)\n* [Chapter 02 - Introduction To Python Programming](#chapter-02---introduction-to-python-programming)\n* [Chapter 03 - Introducing Methods](#chapter-03---introducing-methods)\n* [Chapter 04 - Introduction To Python Platform](#chapter-04---introduction-to-python-platform)\n* [Chapter 05 - Introduction To PyCharm](#chapter-05---introduction-to-pycharm)\n* [Chapter 06 - Introducing Data Types and Conditionals](#chapter-06---introducing-data-types-and-conditionals)\n* [Chapter 07 - Introducing Loops](#chapter-07---introducing-loops)\n* [Chapter 08 - Python Tips](#chapter-08---python-tips)\n* [Chapter 09 - Introducing Object Oriented Programming](#chapter-09---introducing-object-oriented-programming)\n* [Chapter 10 : Python Data Structures](#chapter-10--python-data-structures)\n* [Chapter 11 - Object Oriented Programming Revisited](#chapter-11---object-oriented-programming-revisited)\n* [Chapter 12 - Error Handling](#chapter-12---error-handling)\n* [Chapter 13 - More Python Tips](#chapter-13---more-python-tips)\n\n\n\n## Chapter 01 - Getting Ready with Python\n\n### Installing Python 3, And Launching Python Shell\n\nThis video should help you get up and running with Python 3\n- [Installing Python 3 and Launch Python Shell](https://www.youtube.com/watch?v=4Rx_JRkwAjY)\n\nInstalling Python is really a cakewalk. Search for \"Python download\" on www.google.com. Download the installable and install it.\n\nA quick word of caution on Windows\n- Make sure that you have the check-box \"Add Python 3.6 to PATH\", checked.\n\nOnce you have installed Python, you can launch the Python Shell.\n- Windows - Launch cmd prompt by typing in 'cmd' command.\n- Mac or Linux - Launch up terminal.\n\nCommand to launch Python 3 is different in Mac.\n- In Mac, type in `python3`\n- In other operating systems, including windows, type `python`\n\nYou can type code in python shell and code as well!\n\nYou can use ```print(5*4)```, and it shows ```20```.\n\nYou can execute the code, and the shell would immediately give you output.\n\nUsing the the Python Shell is an awesome way to learn Python.\n\n## Chapter 02 - Introduction To Python Programming\n\nMost programmers find programming a lot of fun, and besides, it also gets their work done.\n\nProgramming mainly involves *problem solving*, where one makes use of a computer to solve a real world problem.\n\nDuring our journey here, we will approach programming in a very different way. We will not only introduce you to the Python language, but also help you pick up essential problem solving skills.\n\nAs a programmer, you need to be able to look at a problem, and identify the important programming concepts relevant to solving it. Finally, you need to be able to use the language features and syntax, to express your solution on the computer. While all this looks complex, we want to make it easy for you. Together, we will tackle a variety of programming challenges, using these same steps. We will start with simple challenges (such as a Multiplication Table), and gradually increase the difficulty level over the duration of this repo.\n\nLearning to program is a lot like learning to ride a bicycle. The first few steps are the most challenging ones.\n\nOnce you get over these initial steps, your experience will become more and more enjoyable.\n\nAre you ready for your first programming challenge? Let's get going now! We wish you all the best.\n\n#### Summary\n\nIn this step, we:\n\n* Were introduced to the concept of problem solving\n* Understood how good programmers approach problem solving\n\n### Step 01: Our First Programming Challenge\n\nOur first *programming challenge* aims to do, what every kid does in math class: read out a multiplication table. We now want to give this task to the computer. Here is the  statement of our problem:\n\n#### The **Print Multiplication Table Challenge (PMT-Challenge)**\n\n1. Compute the multiplication table for ```5```, with entries from ```1``` to ```10```.\n2. Display this table.\n\nThe display needs to be:\n\n**_5 * 1  =  5_**\n\n**_5 * 2  = 10_**\n\n**_5 * 3  = 15_**\n\n**_5 * 4  = 20_**\n\n**_5 * 5  = 25_**\n\n**_5 * 6  = 30_**\n\n**_5 * 7  = 35_**\n\n**_5 * 8  = 40_**\n\n**_5 * 9  = 45_**\n\n**_5 * 10 = 50_**\n\nThis is the challenge. For convenience, let's give it a label, say *PMT-Challenge*. What would be the important concepts we need to learn, to solve this challenge? The following list of concepts would be a good starting point:\n\n* **Statements**\n* **Expressions**\n* **Variables**\n* **Literals**\n* **Conditionals**\n* **Loops**\n* **Methods**  \n\nIn the rest of this chapter, we will introduce these concepts to you, one-by-one. We will also show you how learning each concept, takes us closer to a solution to *PMT-Challenge*.\n\n#### Summary\n\nIn this step, we:\n\n* Stated our first programming challenge\n* Identified what programming concepts we need to learn, to solve this challenge\n\n### Step 02: Breaking Down *PMT-Challenge*\n\nTypically when we do programming, we have problems. Solving the problem typically need a step-by -step approach. Common sense tells us that to solve a complex problem, we break it into smaller parts, and solve each part one by one. Here is how any good programmer worth her salt, would solve a problem:\n\n* Simplify the problem,  by breaking it into sub-problems\n* Solve the sub-problems in stages (in some order), using the language\n* Combine these solutions to get a final solution\n\nThe *PMT-Challenge* is no different! Now how do we break it down, and where do we really start? Once again, your common sense will reveal a solution. As a first step, we could get the computer to calculate say, ```5 * 3```. The second thing we can do, is to try and print the calculated value, in a manner similar to ```5 * 3 = 15```. Then, we could repeat what we just did, to print out all the entries of the ```5``` multiplication table. Let's put it down a little more formally:\n\nHere is how our draft steps look like\n* Calculate ```5 * 3``` and print result as ```15```\n* Print ```5 * 3 = 15``` (```15``` is result of previous calculation)\n* Do this ten times, once for each table entry (going from ```1``` to ```10```)\n\nLet's start with that kind of a game plan, and see where it takes us.\n\n#### Summary\n\nIn this step, we:\n\n* Learned that breaking down a problem into sub-problems is a great help\n* Found a way to break down the *PMT-Challenge* problem\n\n### Step 03: Introducing Operators And Expressions\n\nLet's focus on solving the first sub-problem of *PMT-Challenge*, the numeric computation. We want the computer to calculate  ```5 * 5``` for example, and print ```25``` for us. How do we get it to do that? That's what we would be looking at in this step.\n\n#### Snippet-01: Introducing Operators\n\nLaunch up Python shell. We want to calculate ```5 * 5```. How do we do that?\n\nUsing our knowledge of school math, let's try ```5 X 5```.\n\n```py\n\t\u003e\u003e\u003e 5 X 5\n\tFile \"\u003c stdin \u003e\", line 1\n\t5 X 5\n\t  ^\n\tSyntaxError: invalid syntax\n```\n\nThe Python Shell hits back at us, saying \"*invalid syntax*\". This is how Python complains, when it doesn't fully understand the code you type in. Here, it says our code has a \"**SyntaxError**\".\n\nThe reason why it complains, is because '```X```' is not a valid **operator** in Python.\n\nThe way you can do multiplication is by using the '```*```' *operator* .  \n\n\"*5 into 5*\" is achieved by the code ```5 * 5```, and you can see the result ```25``` being printed. Similarly, ```5 * 6``` gives us ```30```.\n\n```py\n\t\u003e\u003e\u003e 5 * 6\n\t30\n```\n\n\nThere are a wide range of other operators in Python:\n\n* ```5 + 6``` gives a result of ```11```.\n* ```5 - 6``` leads to ```-1```.  \n\n```py\n\t\u003e\u003e\u003e 5 + 6\n\t11\n\t\u003e\u003e\u003e 5 - 6\n\t-1\n\n```\n\n```10 / 2```, gives an output of  ```5.0``` . There is one interesting operator, ```**```. Let's try ```10 ** 3```. We ran this code, and the result we get is ```1000```. Yes you guessed right, the operator performs \"to the power of\". \"```10``` to the power of ```3```\" is ```10 * 10 * 10```, or ```1000```.\n\n```py\n\t\u003e\u003e\u003e 10 / 2\n\t5.0\n\t\u003e\u003e\u003e 10 ** 3\n\t1000\n\n```\n\n\nAnother interesting operator is ```%```,  called \"*modulo*\", which computes the remainder on integer division. If we do ```10 % 3```, what is the remainder when ```10``` is divided by ```3```? ```3 * 3``` is ```9```, and ```10 - 9``` is ```1```, which is what ```%``` returns in this case.\n\n\nLet's look at some terminology:\n\n- Whatever pieces of code we gave Python shell to run, are called **expressions**. So, ```5 * 5```, ```5 * 6``` and ```5 - 6``` are all *expressions*. An expression is composed of *operators* and **operands**.\n- In the expression ```5 * 6```, the two values ```5``` and ```6``` are called operands, and the ```*``` operator *operates* on them.\n- The values ```5``` and ```6``` are **literals**, because those are constants which cannot be changed.\n\n\nThe cool thing about Python, is that you can even have expressions with multiple operators. Therefore, you can form an expression with ```5 + 5 + 5```, which evaluates to ```15```. This is an expression which has three operands, and two ```+``` operators. You can even have expressions with different types of operators, such as in ```5 + 5 * 5```.\n\n```py\n\t\u003e\u003e\u003e 5 + 5 + 5\n\t15\n\t\u003e\u003e\u003e 5 + 5 * 5\n\t30\n\n```\n\n\nTry and play around with the expressions, and understand the output which results.\n\n#### Summary\n\nIn this step, we:\n\n* Learned how to give code input to the Python Shell\n* Understood that Python has a predefined set of operators\n* Used a few types of basic operators and their operands, to form expressions\n\n### Step 04: Programming Exercise IN-PE-01\n\nAt this stage, your smile tells us that you enjoy evaluating Python expressions. What if we tickle your mind a bit, to make sure it hasn't fallen asleep? Here is your first programming exercise.\n\n#### Exercises\n\n1. Write an expression to calculate the number of minutes in a day.\n2. Write an expression to calculate the number of seconds in a day.\n\n##### Note\n\nYou need to solve these problems by yourself. If you are able to work them out, that's fantastic! But if not, that's part of the learning process.\n\n#### Solutions\n\n#### Solution 1\n\n```py\n\t\u003e\u003e\u003e 24 * 60\n\n\t1440\n\n\n```\n\nWe wanted to calculate the number of minutes in a day. How do we do that? Think about this...\n\n* How many number of hours are there in a day? ```24```.\n* And how many minutes does each hour have? It's ```60```.\n* So if you want to find out the number of minutes in a day, it's ```24 * 60```, which is ```1440```.\n\n#### Solution 2\n\n```py\n\t\u003e\u003e\u003e 24 * 60 * 60\n\n\t86400\n\n\n```\n\nHow many seconds are there in a day?\n\n* Let's start with the number of hours, ```24```.\n* The number of minutes in an hour is ```60```, and\n* The number of seconds in a minute is ```60``` as well.\n* So it's ```24 * 60 * 60```, or ```86400```.\n\n#### Summary\n\nIn this step, we:\n\n* Solved a Programming Exercise involving common scenarios, using Python code involving:\n\t* Expressions\n\t* Operators\n\t* Literals\n\n### Step 05: Puzzles On Expressions\n\nLet's look at a few puzzles related to expressions, in this step. Before that, let's revise some of the terminology we had learned earlier.\n\n```5 + 6 + 10``` is an example of an expression. In this expression, ```5```, ```6``` and ```10``` are operands. The ```+``` here is the operator. You can have multiple operators in an expression. We also did mention that the operands, namely ```10```, ```6``` and ```5```, are literals. Their values will not change.\n\nHere are a few puzzles coming up, to explore aspects of expressions.\n\n#### Snippet-01: Puzzles On Expressions\n\nThink about what would happen when you do something of this kind: ```5 $ 2```. You're right, it would throw a ```SyntaxError```. When Python does not understand the code you type in, it reports an error. Here, the expression we're typing is ```5 $ 2```, which does not make sense to Python, hence the ```SyntaxError```.\n\n```py\n\t\u003e\u003e\u003e 5 $ 2\n\tFile \"\u003c stdin \u003e\", line 1\n\t5 $ 2\n\t^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e 5$2\n\tFile \"\u003c stdin \u003e\", line 1\n\t5 $ 2\n\t^\n\tSyntaxError: invalid syntax\n\n```\n\n\n\nLet's say we type in ```5+6+10```, without any spaces between the operands, and the operators. What do you think will happen? Surprisingly, the Python Shell does calculate the value!\n\n```py\n\t\u003e\u003e\u003e 5+6+10\n\t21\n\n```\n\n In an expression, using spaces makes it easier for you to read it, but it's not mandatory. ```5 + 6 + 10``` is easier to read than ```5+6+10```,  but does not make any difference to the Python compiler.\n\nThe next puzzle tries to evaluate ```5 / 2```, which is \"```5``` divided by ```2```\". What would be the output? ```2.5```.\n\n```py\n\t\u003e\u003e\u003e 5/2\n\t2.5\n\n```\n\nIf you're coming from other programming languages like Java or C, this might be a surprising result. If you try this in Java for instance, you would get ```2``` as the output. Note that even though both operands are integers, the result of the ```/``` operation is a floating point value, ```2.5``` . Python does what is expected by a programmer!\n\n\n\nThe puzzle after that tries to play with ```5 + 5 * 6```. What would be the result of this expression? Will it be ```5 + 5``` or ```10```, then ```10 * 6```, which is ```60```? Or, will it be ```5``` plus ```5 * 6```, which is ```5``` + ```30```, that's ```35```?\n\n```py\n\t\u003e\u003e\u003e 5 + 5 * 6\n\t35\n```\n\nThe correct result is ```35```.\n\nPython decides this is based on the **precedence** of operators.\n\nOperators in Python are divided into two sets as follows:\n*   ```**```, ```*```,  ```/``` and ```%``` have higher precedence, or priority.\n*   ```+``` and ```-``` have a lower precedence.\n\nSub-expressions involving operators from {```*```, ```/```, ```%```, ```**```} are evaluated before those involving operators from {```+```, ```-```}\n\nLet's try another small puzzle on precedence, with ```5 - 2 * 2```. What would be the result of this? Will it be ```6```, or ```1```? It's ```1```, because ```*``` has a higher precedence than ```-```. Thus ```2 * 2``` is ```4```, and ```5 - 4``` gives us ```1```.\n\n```py\n\t\u003e\u003e\u003e 5 - 2 * 2\n\t1\n\n```\n\nLet's say we want to execute ```5 - 2```, to give an output of ```2```. How do we change the operator precedence?\n\nYou cannot really change the precedence, but you can add parentheses to group sub-expressions differently.\n\n```py\n\t\u003e\u003e\u003e (5 - 2) * 2\n\t6\n\t\u003e\u003e\u003e 5 - ( 2 * 2 )\n\t1\n\n```\n\n Parentheses have the highest precedence in Python, and can be used to override operator precedence.  ```(5 - 2)``` gets calculated first, and the final result of the expression is ```6```.\n\nA positive thing about using parentheses is, that it makes expressions more readable. So even in situations such as ```5 - 2 * 2```, where we know the result according to precedence, adding parentheses is good.\n\n#### Summary\n\nIn this step, we went about solving a few puzzles about expressions, touching concepts such as:\n* ```SyntaxError``` for incorrect operators\n* White-space in expressions\n* Floating Point division by default\n* Operator Precedence\n* Using parentheses\n\n### Step 06: Printing Text\n\nIn the previous step, we learned how to use expressions to compute values. In this step, let's see how we can actually print multiplication table entries, that are readable by the user.\n\n#### Snippet-01: Printing Text\n\nHow do we go about printing a complete multiplication table entry? We want to print text such as  ```5 * 6 = 30``` . But trying to do so, as we know it, gives us a ```SyntaxError```. Clearly, there is a different way to print text, as compared to an expression.\n\n```py\n\t\u003e\u003e\u003e 5 * 6 = 30\n\t  File \"\u003cstdin\u003e\", line 1\n\tSyntaxError: can't assign to operator\n\n```\n\nLet's first try to print a simple piece of text, ```Hello```. Typing in this piece of code directly on Python Shell also gives us an error.\n\n```py\n\t\u003e\u003e\u003e Hello\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'Hello' is not defined\n\n```\n\nOnly expressions work that way, and ```Hello``` is not really an expression.\n\n```\"Hello\"``` is typically called a **string**, and represents the text of letters ```'H'```, ```'e'```, ```'l'```, ```'l'```, ```'o'```. ```\"Hello\"``` is hence different from the number ```5```.\n\nThere are a number of in-built functions in Python to help print strings. One of these is the ```print()``` function. Can you just say ```print Hello```?\n\n```py\n\t\u003e\u003e\u003e print Hello\n\t  File \"\u003cstdin\u003e\", line 1\n\t    print Hello\n\t              ^\n\tSyntaxError: Missing parentheses in call to 'print'. Did you mean print(Hello)?\n```\n\nThe Python compiler gives you an error, that says \"missing parentheses\".\n\nWill ```print(Hello)``` work?\n\n```py\n\t\u003e\u003e\u003e print (Hello)\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'Hello' is not defined\n\n```\n\nNope! Again, this one failed because you need to indicate that ```\"Hello\"``` is a string.\n\nHow do I indicate that ```\"Hello\"``` is a string? By putting it within double quotes.\n\nLet's try `print (\"Hello\")`\n\n```py\n\t\u003e\u003e\u003e print (\"Hello\")\n\tHello\n\t\u003e\u003e\u003e print(\"Hello\")\n\tHello\n\n```\n\n```print(\"Hello\")``` finally results in ```\"Hello\"``` being printed out. To be able to print ```\"Hello\"```, the things we need to do are:\n\n*  Typing the method name print ,\n*  open parentheses ( ,\n*  Followed by a double quote \" ,\n*  The text Hello,\n*  and another double quote \" ,\n*  finished off with a closed parentheses ).\n\nWhat we have written here is called a **statement**, a simple piece of code to execute. As part of this statement, we are **calling** a **function**, named ```print()```.\n\nWhat exactly are we trying to print?\n\nThe text ```\"Hello\"```, which is called a **parameter** or **argument**,  to ```print()```.\n\nNow let's get back to what we wanted to do, which is to print ```5 * 6 = 30```. The most basic version would be something of this kind, ```print(\"5 * 6 = 30\")```. Here, we are passing the entire value in the form of a string.\n\n```py\n\t\u003e\u003e\u003e print(\"5 * 6 = 30\")\n\t5 * 6 = 30\n\n```\n\nThis prints the text on the console, as-is. The thing you need to understand here is, we aren't really calculating ```30``` using the formula ```5 * 6```, but directly putting text ```30``` in here. That's called **hard-coding**.\n\nIn a later step, we will look at how to actually calculate the value and pass it in.\n\n#### Summary\n\nIn this step, we:\n\n* Understood that displaying text on the console is not the same as printing an expression value\n* Learned about the ```print()``` function, that is used to print text in Python.\n* Found a way to print the text ```\"5 * 6 = 30\"``` on the console, by hard-coding values in a string\n\n### Step 07: Puzzles On Utility Methods, And Strings\n\nIn the previous step, we learned how to print ```5 * 6 = 30```. It was not a perfect solution, because we hard-coded everything.  we used an in-built function named ```print()```, passed a string to it, and invoked the method.\n\nIn this step, let's look at a number of puzzles related to in-built methods, their parameters, and strings in general.\n\nFor example, let's do ```print(\"5 * 6\")```, as in the previous step. What does this code result in?\n```py\n\t\u003e\u003e\u003e print(\"5*6\")\n\t5*6\n\t\u003e\u003e\u003e print('5*6')\n\t5*6\n\n```\n\nIt just prints the string ```\"5 * 6\"```.\n\nLet's say we try the code ```print(5 * 6)```,\n\n```py\n\t\u003e\u003e\u003e print(5*6)\n\t30\n\n```\n\nWithout the double quotes, ```5 * 6``` is an expression. What will be the output? ```30```.\n\nIf you call ```print()``` with an expression argument, it prints the value of the expression. However, when we pass something within double quotes, it becomes a piece of text, printed as-is.\n\nAn interesting thing to note is, that in Python you can use either double-quotes (```\"``` and ```\"```), or single-quotes (```'``` and ```'```) with text values.\n\nLet's look at a few other in-built methods within Python.\n\nConsider ```abs()``` (which stands for absolute value), a method that accepts a numeric value. You can use ```abs(10.5)```, passing ```10.5``` as a value to it, and it prints the absolute value of ```10```.\n```py\n\t\u003e\u003e\u003e abs 10.5\n\t  File \"\u003cstdin\u003e\", line 1\n\t    abs 10.5\n\t           ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e abs(10.5)\n\t10.5\n```\n\nIf you pass in a string value, will it work? It complains, \"```abs()``` function will not work with a string, it only works with numeric values\".\n\n```py\n\t\u003e\u003e\u003e abs(\"10.5\")\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tTypeError: bad operand type for abs(): 'str'\n\n```\n\nLet's say you want to use a function that computes \"to the power of\", for instance \"```2``` to the power of ```5```\". In Python, there's an in-built function named ```pow()```, which does just what we need. To ```pow()```, you can pass two parameters and calculate the result. How do you do that?  \n\n\nWill this work: ```pow 2 5```? No, not at all. This code does not work as well: ```pow(2 5)```. ```pow(2, 5)``` is the correct syntax.  \n```py\n\t\u003e\u003e\u003e pow 2 5\n\t  File \"\u003cstdin\u003e\", line 1\n\t    pow 2 5\n\t        ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e pow(2 5)\n\t  File \"\u003cstdin\u003e\", line 1\n\t    pow(2 5)\n\t          ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e pow(2, 5)\n\t32\n```\n\n\nYou'll see that ```32``` is printed.\n\nLet's see another example, \"```10``` to the power of ```3```\". ```pow(10,3)``` is the alternative to saying ```10 ** 3```. This gives us ```1000```, similar to how ```pow()``` would.\n\n```py\n\t\u003e\u003e\u003e pow(10, 3)\n\t1000\n\t\u003e\u003e\u003e 10 ** 3\n\t1000\n\n```\n\n```max()``` returns maximum in a set of numbers.```min()``` function returns the minimum value.\n```py\n\t\u003e\u003e\u003e max(34, 45, 67)\n\t67\n\t\u003e\u003e\u003e min(34, 45, 67)\n\t34\n\n```\n\n\n\n\nThese are some of the in-built functions in Python, and we saw how to call the in-built functions by passing in a varied number of parameters.\n\nPython is case sensitive. So let's say I want of calculate  ```pow(2,5)```. So this would give me ```32```. Now, what if I say capital ```'P'``` instead of small ```'p'``` here? ```Pow(2,5)``` would lead to an error.\n\n```py\n\t\u003e\u003e\u003e pow(2,5)\n\t32\n\t\u003e\u003e\u003e Pow(2,5)\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'Pow' is not defined\n\n```\nThe only things not case-sensitive in Python, are string values. Earlier we saw that the code ```print(\"Hello\")``` displays the text ```\"Hello\"```. Inside a string, the text can be in any case. Hence, ```print(\"hello\")``` displays ```\"hello\"``` ,with a small ```'h'```.\n\n```py\n\t\u003e\u003e\u003e print(\"Hello\")\n\tHello\n\t\u003e\u003e\u003e print(\"hello\")\n\thello\n\t\u003e\u003e\u003e print(\"hellO\")\n\thellO\n\t\u003e\u003e\u003e print ( \"hellO\" )\n\thellO\n\n```\n\nHowever inside your code, you need to be very particular about the case of function names, class names, variable names, and the like.\n\nIn your code, whitespace does not really matter. You can add space here and here, and you would still get the same output. However, in case of strings, whitespace does matter.\n\nIf we say ```print(\"hellO World\")```, it would print ```\"hellO World\"```, with a space in between. And if you do ```print(\"hellO   World\")``` with three spaces, it would print the same. In expressions, white-space does not affect the output.\n\n```py\n\t\u003e\u003e\u003e print ( \"hellO World\" )\n\thellO World\n\t\u003e\u003e\u003e print ( \"hellO     World\" )\n\thellO     World\n\n```\n\n\nThe last thing we want to look at, is an **escape sequence**. Let's say you want to print a double quote, ```\"```, in the code.  If we were to do this: ```print(\"Hello\"\")```, what would happen? The compiler says error!\n\n\n```py\n\t\u003e\u003e\u003e print(\"Hello\"\")\n\t  File \"\u003cstdin\u003e\", line 1\n\t    print(\"Hello\"\")\n\t                  ^\n\tSyntaxError: EOL while scanning string literal\n\n```\n\nIf you want to print a ```\"``` inside a string, use an escape sequence. In Python, the symbol ```'\\'``` is used as an **escape character**. On using ```'\\'``` adjacent to the ```\"```, it prints  ```Hello\"``` (notice the trailing ```\"```). We have used the ```'\\'``` to **escape** the ```\"```, by forming an *escape sequence* ```\\\"```.\n\n```py\n\u003e\u003e\u003e print(\"Hello\\\"\")\nHello\"\n\u003e\u003e\u003e\n\n```\n\nThe other reason why you would want to use a ```'\\'``` is to print a ```\u003cNEWLINE\u003e```. If you want to print ```\"Hello World\"```, but with ```\"Hello\"``` on one line and ```\"World\"``` on the next, ```'\\n'``` is the escape sequence to use.\n```py\n\t\u003e\u003e\u003e print(\"Hello\\nWorld\")\n\tHello\n\tWorld\n```\n\nThe other important escape sequence is ```'\\t'```, which prints a ```\u003cTAB\u003e``` in the output. When you do ```print(\"Hello\\tWorld\")```, you can see the tab-space between ```\"Hello\"``` and ```\"World\"```.\n\n```py\n\t\u003e\u003e\u003e print(\"Hello\\tWorld\")\n\tHello\tWorld\n\n```\n\nAnother useful escape sequence is ```\\\\``` . If you want to print a ```\\``` , then use the sequence ```\\\\``` . You would see that it prints ```Hello\\World``` . Think about what would happen if we put six ```\\``` . Yes you're right! It would print this string: ```\"\\\\\\\"``` .\n\n```py\n\t\u003e\u003e\u003e print(\"Hello\\\\World\")\n\tHello\\World\n\t\u003e\u003e\u003e print(\"Hello\\\\\\\\\\\\World\")\n\tHello\\\\\\World\n\n```\n\nOne of the things with Python is, it does not matter whether you use double quotes or single quotes to enclose strings. There are some interesting, and useful ways of using a combination of both, within the same string. Have a look at this call: ```print(\"Hello'World\")```, and notice the output we get. In a similar way, the following code will be accepted and run by the Python system: ```print('Hello\"World')```.\n\n\n```py\n\t\u003e\u003e\u003e print('Hello\"')\n\tHello\"\n\t\u003e\u003e\u003e print(\"Hello'World\")\n\tHello'World\n\t\u003e\u003e\u003e print(\"Hello\\\"World\")\n\tHello\"World\n\t\u003e\u003e\u003e print(\"Hello\\\"World\")\n\tHello\"World\n\n```\n\nThe above two examples can be used as a tip by newbie programmers when they form string literals, and want to use them in their code:\n* If the string literal contains one or more single quotes, then you can use double quotes to enclose it.\n* However if the string contains one or more double quotes, then prefer to use single quotes to enclose it.\n\n#### Summary\n\nIn this step, we:\n\n* Explored a number of puzzles related to code involving:\n\t* Built-in functions for numeric calculations\n\t* The ```print()``` function to display expressions and strings\n* Covered the following aspects of the above utilities:\n\t* Case-sensitive aspects of names and strings\n\t* The role played by whitespace\n\t* The escape character, and common escape sequences\n\n### Step 08: Formatted Output With print()\n\nIn the previous step, we learned how to print a hard-coded string, such as ```\"5 * 6 = 30\"```.\n\nIn this step, let's try to replace the hard-coded ```30``` with a computed value.\n\nLet's start with a simple scenario. Let's say we want to place that calculated value within a string, and display it. How do we do that?\n\n\n\n#### Snippet-01: print() Formatted Output\n\n`format()` method can be used to print formatted text.\n\nLet's see an example:\n\n```py\n\t\u003e\u003e\u003e print(\"VALUE\".format(5*2))\n\tVALUE\n\n```\nWe were expecting ```10``` to be printed, but it's actually printing ```VALUE```.\n\nHow do we get ```10``` to be printed then?\n\n```py\n\t\u003e\u003e\u003e print(\"VALUE {0}\".format(5*2))\n\tVALUE 10\n\n```\n\nBy having an open brace ```{```,  closed brace ```}```, and and by putting the index of the value between them. Here, the value is the first parameter, and it's index will be ```0```.\n\n```\"VALUE {0}\"``` is what we need.\n\n\nLet's take another example. Suppose to the ```format()``` function, we pass three values: ```10```, ```20``` and ```30```.\n\nTypically when we count positions or indexes, we start from ```0```.\n\nTo print the first value, you need to pass in an index of ```0```. To print the second value, pass an index of ```1```.\n\n```py\n\t\u003e\u003e\u003e print(\"VALUE {0}\".format(10,20,30))\n\tVALUE 10\n\t\u003e\u003e\u003e print(\"VALUE {1}\".format(10,20,30))\n\tVALUE 20\n\t\u003e\u003e\u003e print(\"VALUE {2}\".format(10,20,30))\n\tVALUE 30\n\n```\n\nNow going back to our problem, we wanted to display  ```\"5 * 6 = 30\"```, but without hard-coding. Instead of ```30```, we want the calculated value of ```5 * 6```.\n\n```py\n\t\u003e\u003e\u003e print(\"5 * 6 = 30\".format(5,6,5*6))\n\t5 * 6 = 30\n```\n\nLet replace `\"5 * 6 = 30\"` with `\"5 * 6 = {2}\"`. `2` is the index of parameter value `5*6`.\n\n```py\n\t\u003e\u003e\u003e print(\"5 * 6 = {2}\".format(5,6,5*6))\n\t5 * 6 = 30\n\n```\n\nCool! Progress made.\n\nLet's replace `5 * 6` with the right indices - `{0} * {1}`.\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,6,5*6))\n\t5 * 6 = 30\n\n```\n\nThe great thing about this, is now we can replace the values we passed to ```print()``` in the first place, without changing the indexes! So, we can display results for   ```5 * 7 = 35``` and ```5 * 8 = 40```. We are now able to print ```5 * 6 = 30```, ```5 * 7 = 35```, ```5 * 8 = 40```, and can do similar things for other table entries as well.\n\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,7,5*7))\n\t5 * 7 = 35\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,8,5*8))\n\t5 * 8 = 40\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,8,5*8))\n\t5 * 8 = 40\n\n```\n\n#### Summary\n\nIn this step, we:\n\n* Discovered that Python provides a way to do formatted printing of string values\n* Looked at the ```format()``` function, and saw how to call it within ```print()```\n* Observed how we could work only with the indexes of parameters to ```format()```, and change the parameters we pass without changing the code\n\n### Step 09: Puzzles On format() and print()\n\nIn this step, let's look at a few puzzles related to the format, and the print methods.\n\n#### Snippet-01: format() And print() Puzzles\n\nLet's say we pass in additional values, such as: ```5 * 8```, ```5 * 9``` and ```5 * 10```. However, within the call to ```format()```, we are only referring to the values at index ```0```, index ```1``` and index ```2```. The values at indexes ```3``` and ```4``` are not used at all. What would happen when we run the code?\n\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,8,5*8,5*9,5*10))\n\t5 * 8 = 40\n\n```\n\nWould this throw an error? No, it does not. You can see that the additional values which are passed in, are conveniently ignored.\n\nLet's say instead of passing in a value of ```2```, we pass ```4```. What would happen?\n\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {4}\".format(5,8,5*8,5*9,5*10))\n\t5 * 8 = 50\n\n```\n\n```5 * 10``` is the value at index ```4```\n\n\nNow let's take a different scenario. We remove all the parameters passed to ```format()```. However, inside the call to ```print()```,  we continue to say ```{0} * {1} = {4}```. So we are trying to print the value at index ```4```, but are only passing two values to the function ```format()```. What do you think will happen?\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {4}\".format(5,8))\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tIndexError: tuple index out of range\n\n```\n\nIt says ```IndexError```, which means :\"you are asking me to fetch the value at index ```4```, but only passing in two values. How can I do what you want?\"\n\nLet's look at a few more things related to other data types. We try to format the following inside ```print()```: ```{0} * {1} = {2}```,  and would pass in ```2.5```, ```2```, and  ```2.5 * 2``` . Here, ```2``` is an integer value, but ```2.5``` is a floating point value. You can see that it prints ```2.5 * 2 = 5.0```.  So this approach of formatting values with ```print()```, works also with floating point data as well.\n\n\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(2.5,2,2.5*2))\n\t2.5 * 2 = 5.0\n\n```\n\nNow, are there are other types of data that ```format()``` works with? Yes, strings can join the party.\n\nLet's say over here, we do: ```print(\"My name is {0}\".format(\"Ranga\"))```. What would happen?\n\n```py\n\t\u003e\u003e\u003e print(\"My name is {0}\".format(\"Ranga\"))\n\tMy name is Ranga\n\n```\n\nIndex ```0``` will be replaced with the first parameter to ```format()```.\n\n#### Summary\n\nIn this step, we:\n\n* Understood the behavior when the parameters passed to ```format()```:\n\t* Exceed the indexes accessed by ```print()```\n\t* Are less than the indexes accessed by ```print()```\n\t* Are of type integer, floating-point or string\n\n### Step 10: Introducing Variables\n\nWe are slowly making progress toward our main goal, which is to print the ```5``` multiplication table.\n\nIn the first statement, we are printing ```5 * 1 = 5```, and then changing the literals. To make it print ```5 * 2 = 10```, we are changing ```1``` to ```2```. Next, we are changing ```2``` to ```3```. How do we make it a little simpler, so that our effort is reduced?\n\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,1,5*1))\n\t5 * 1 = 5\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,2,5*2))\n\t5 * 2 = 10\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,3,5*3))\n\t5 * 3 = 15\n\n```\n\nLet's try a different approach.\n\nWhat would happen if you replace ```1``` with ```index```, and ```5 * 1``` with ```5 * index```, and try to run it?  \n\n\nIt gives an error! It says: \"index is not defined\".\n\nLet's try and fix this, and execute ```index = 2```. What would happen?\n\n```py\n\t\u003e\u003e\u003e index = 2\n\n```\n\nAha! This compiles.\n\n```py\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 2 = 10\n```\n\nAnd this statement is printing ```5 * 2 = 10```.\n\nLet's try something else. Let's make ```index = 3```. What would happen?\n\n```py\n\t\u003e\u003e\u003e index = 3\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 3 = 15\n\n```\n\nThe same statement on being run, prints ```5 * 3 = 15```.\n\nHow can you check the value that ```index``` has? Just type in ```index```.\n\n```py\n\t\u003e\u003e\u003e index\n\t3\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 3 = 15\n```\n\n\nThe ```index``` symbol we have used here, is what is called a **variable**.\n\nIn Python, it's also called a **name**.\n\nYou can see that the value ```index``` referring to, can change over the duration of a program.\n\nInitially, ```index``` was referring to a value of ```1```. later, ```index``` was referring to a value of ```3```.\n\n\nNow, think about how you would print the entire table. All that you need to do, is start from ```1```, execute the same statement with ```print()``` and ```format()```, to get output ```5 * 1 = 5```. Next, Change the value of index to ```2```, and then print the same statement. Next, ```index = 3```, and print the same statement again.\n\n```py\n\t\u003e\u003e\u003e index = 1\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 1 = 5\n\t\u003e\u003e\u003e index = 2\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 2 = 10\n\t\u003e\u003e\u003e index = 3\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 3 = 15\n\n```\n\nWith the same statement `print(\"{0} * {1} = {2}\".format(5,index,5*index))`, we are able to print different values. The value of ```index``` varies, but the code remains the same!\n\nVariables make the program much more easier to read, as well as more generic.\n\n#### Snippet-02: Classroom Exercise On Variables\n\nLet's do a simple exercise with variables.\n\nWe want to create three variables ```a```, ```b``` and ```c```. Let's initially give them some values, say a value of ```5``` to ```a```, ```6``` to ```b``` and ```7``` to ```c```.\n\nWe want to get output of this kind: ```5 + 6 + 7 = 18```, without using the literal values.\n\nYou would want to use the values stored in the variables in ```a```, ```b``` and ```c```.\n\nIf you're hard-coding, the way to do it is with ```print(\"5 + 6 + 7 = 18\")```.\n\n```py\n\t\u003e\u003e\u003e a = 5\n\t\u003e\u003e\u003e b = 6\n\t\u003e\u003e\u003e c = 7\n\t\u003e\u003e\u003e print(\"5 + 6 + 7 = 18\")\n\t5 + 6 + 7 = 18\n\t\u003e\u003e\u003e print(\"5 + 6 + 7 = 18\".format(a,b,c,a+b+c))\n\t5 + 6 + 7 = 18\n```\n\nThe way you can do that is with code like this: ```print(\"{0} + {1} + {2} = {3}\".format(a,b,c,a+b+c))```.\n```py\n\t\u003e\u003e\u003e print(\"{0} + {1} + {2} = {3}\".format(a,b,c,a+b+c))\n\t5 + 6 + 7 = 18\n```\n\nHow do you confirm we are accessing values stored in the variables?\n\nLet's change the values of ```a```, ```b``` and ```c```. Let's make ```a = 6``` , ```b = 7``` , and ```c = 8``` . Execute same statement.\n\n```py\n\t\u003e\u003e\u003e a = 6\n\t\u003e\u003e\u003e b = 7\n\t\u003e\u003e\u003e c = 8\n\t\u003e\u003e\u003e print(\"{0} + {1} + {2} = {3}\".format(a,b,c,a+b+c))\n\t6 + 7 + 8 = 21\n\n\n```\nYou can see the magic of variables at play here! Based on what values these variables are referring to, you can see that the output of the print statement changes.\n\n#### Summary\n\nIn this step, we:\n* Were introduced to variables, or names, in Python\n* Observed how we could pass in values of variables to the ```format()``` function\n\n### Step 11: Puzzles On Variables\n\nIn the previous step, we were introduced to the concept of variables in Python.\n\nWe will start with looking at a few puzzles.\n\n#### Snippet-01: Puzzles On Variables\n\nWhat if I try to refer to a variable which is not yet created?\n\n```py\n\t\u003e\u003e\u003e count\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'count' is not defined\n\t\u003e\u003e\u003e print(count)\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'count' is not defined\n```\n\nBefore using a variable, you need to have it assigned a value. If you have not defined a variable before, then you cannot use it. Consider  ```print(count)```, it does not know what count is. So it would throw an error, saying: \"```count``` is not defined, I have no idea what count is.\"\n\nOnce you assign a value to a variable, you can use it.\n\n```py\n\t\u003e\u003e\u003e count = 4\n\t\u003e\u003e\u003e print(count)\n\t4\n\n```\nThe statement ```count = 4``` where we are creating a variable named ```count``` for the first time, is called a **variable definition**.\n\nThis is the first time you're referring to a variable, and assigning a value to it.\n\nPython will create a variable in its memory.\n\nVariable names are case sensitive. `count` and `Count` are not the same thing.\n\n```py\n\t\u003e\u003e\u003e Count\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'Count' is not defined\n\t\u003e\u003e\u003e count\n\t4\n```\n\nThere are rules to follow while naming variables.\n\nAll variable names should either start with an alphabet , or an underscore ```_``` .\n`count`, `_count` are valid. `1count` is invalid.\n\n```py\n\t\u003e\u003e\u003e 1count = 5\n\t  File \"\u003cstdin\u003e\", line 1\n\t    1count = 5\n\t         ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e count = 5\n\t\u003e\u003e\u003e _count = 5\n\t\u003e\u003e\u003e 1count\n\t  File \"\u003cstdin\u003e\", line 1\n\t    1count\n\t         ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e 2count\n\t  File \"\u003cstdin\u003e\", line 1\n\t    2count\n\t         ^\n\tSyntaxError: invalid syntax\n\n```\n\nAfter the first symbol, you can also use a numeral in variable names.\n\n```py\n\t\u003e\u003e\u003e c12345 = 5\n\n```\n\nTo summarize the rules for naming variables.\n\n* This should start with an alphabet (a capital or a small alphabet) or underscore.\n* Starting the second character, it can be alphabet, or underscore, or a numeric value.\n\n\n#### Summary\n\nIn this step, we:\n\n* Understood that a variable needs to be defined before it is used\n* Learned that there are certain rules to be followed while giving names to variables\n\n### Step 12: Introducing Assignment\n\nIn this step, we will look at an important concept in Python, called **assignment**. In previous steps, we created variables, like ```i = 5```.\n\n#### Snippet-01: Introducing Assignment\n\nYou can create other variables using whatever value ```i``` is referring to. If we say ```j = i```, what would happen?\n\n```py\n\t\u003e\u003e\u003e i = 5\n\t\u003e\u003e\u003e j = i\n\t\u003e\u003e\u003e j\n\t5\n\n```\n```j``` would start referring to the same value that ```i``` is referring to. This statement is called an **assignment**.\n\nLet's try ```j = 2 * i```.\n\n```py\n\t\u003e\u003e\u003e j = 2 * i\n\t\u003e\u003e\u003e j\n\t10\n\n```\n\n`j` refers to a value of `10`\n\n\n```=``` has a different meaning in programming compared to mathematics.\n\nIn mathematics, When we execute  ```j = i```, it means ```j``` and ```i``` are equal.\n\nIn prgramming, the value of the expression on right hand side is assigned to the variable on the right hand side.\nCan you use a constant on the left hand side of an assignment? The answer is \"No\"!\n\n```py\n\t\u003e\u003e\u003e 5 = j\n\t  File \"\u003cstdin\u003e\", line 1\n\tSyntaxError: can't assign to literal\n\n```\n\nThe Python Shell throws an error, saying \"Can't assign to literal\", as ```5``` is a literal.\n\nLet's create a couple of variables. ```num1 = 5``` and ```num2 = 3```. We would want to add these and create a fresh variable. Let's say the name of the variable is ```sum```.\n\n```py\n\t\u003e\u003e\u003e num1 = 5\n\t\u003e\u003e\u003e num2 = 3\n\t\u003e\u003e\u003e sum = num1 + num2\n\t\u003e\u003e\u003e sum\n\t8\n\n```\n\nCreate 3 variables ```a```, ```b``` and ```c``` with different values and calculate their sum.\n\n```py\n\t\u003e\u003e\u003e a = 5\n\t\u003e\u003e\u003e b = 6\n\t\u003e\u003e\u003e c = 7\n\t\u003e\u003e\u003e sum = a + b + c\n\t\u003e\u003e\u003e sum\n\t18\n\n```\n\nWe have just seen the mechanics of how assignment works in Python.\n\n#### Summary\n\nIn this step, we:\n* Learned what happens when you assign a value to a variable, which may or may not exist\n* Discovered that literal constants cannot be placed on the left hand side of the assignment(`=`) operator\n\n### Step 13: Introducing Formatted Printing\n\nUntil now, we have been using the ```format()``` method to format and print values. Let's see a better approach to printing values.\n\nThis is the approach we used until now.\n\n```py\n\t\u003e\u003e\u003e a = 1\n\t\u003e\u003e\u003e b = 2\n\t\u003e\u003e\u003e c = 3\n\t\u003e\u003e\u003e sum = a + b + c\n\t\u003e\u003e\u003e print(\"{0} + {1} + {2} = {3}\".format(a, b, c ,sum))\n\t1 + 2 + 3 = 6\n```\n\nPython has the concept of formatted strings. The syntax to use a formatted string is very simple - `f\"\"`.\n\nIf we want to print the value of a variable ```a```, we can use ```{a}``` in the text.\n\n```py\n\t\u003e\u003e\u003e print(f\"\")\n\t\u003e\u003e\u003e print(f\"value of a is {a}\")\n\tvalue of a is 1\n\t\u003e\u003e\u003e print(f\"value of b is {b}\")\n\tvalue of b is 2\n\n```\n\n The variable within braces is replaced by its value.\n\n You can use expressions in a formatted string. Example below uses `{a+b}`.\n\n```py\n\t\u003e\u003e\u003e print(f\"sum of a and b is {a + b}\")\n\tsum of a and b is 3\n```\n\nThis feature was introduced in a Python 3 release.\n\nLet's get back to the original problem we wanted to solve: printing ```5 + 6 + 7 = 18```, using formatted strings.\n\n```py\n\t\u003e\u003e\u003e print(f\"{a} + {b} + {c} = {sum}\")\n\t1 + 2 + 3 = 6\n```\n\nYou can see how easy it turns out to be!\n\n\n### Step 14: The PMT-Challenge Revisited\n\nWe want to print the ```5```-table from ```5 * 1 = 5``` onward, until we reach to ```5 * 10 = 50```. The best solution we have right now, is shown below:\n\n#### Snippet-01:\n\n```py\n\t\u003e\u003e\u003e index = 1\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 1 = 5\n\t\u003e\u003e\u003e index = 2\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 2 = 10\n\t\u003e\u003e\u003e index = 3\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 3 = 15\n\t\u003e\u003e\u003e index = 4\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 4 = 20\n\n```\n\nCan we do something, to make sure that the code remains the same all the time, but the ```index``` value gets updated?\n\n```py\n\t\u003e\u003e\u003e index = index + 1\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 5 = 25\n\t\u003e\u003e\u003e index = index + 1\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 6 = 30\n\t\u003e\u003e\u003e index = index + 1\n\t\u003e\u003e\u003e print(\"{0} * {1} = {2}\".format(5,index,5*index))\n\t5 * 7 = 35\n\n```\n\nWe used ```index = index + 1``` to increment `index` value.\n\nIf we execute these same two statements again and again, we can print the entire table!\n\nThis is exactly what loops help us do: execute the same statements repeatedly.\n\nThe simplest loop available in Python is the **for loop**.\n\nWhen we run a ```for``` loop, we need to specify the range of values - ```1``` to ```10``` or ```1``` to ```20```, and so on. `range()` function helps us to specify a range of values.\n\n```py\n\t\u003e\u003e\u003e range(1,10)\n\trange(1, 10)\n```\n\nThe syntax of the ```for``` loop is: ```for i in range(1, 10): ...```. Here, ```i``` is the name of the **control variable**. In Python, you need to put a colon, '```:```', and in the next line give indentation.\n\n```py\n\t\u003e\u003e\u003e for i in range(1,10):\n\t...   print(i)\n\t...\n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\n\t8\n\t9\n\n```\n\nYou would see that it prints from ```1``` to ```9```.\n\nWhen we run a loop in ```range(1, 10)```, ```1``` is *inclusive* and ```10``` is **exclusive**.The loop runs from ```1``` to the value before ```10```, which is ```9```.\n\nThe leading whitespace before `print(i)` is called **indentation**. We'll talk about indentation later, when we talk about puzzles related to the ```for``` loop.\n\nHow can you extend this concept to solving our *PMT-Challenge* problem?\n\n```py\n\t\u003e\u003e\u003e print(f\"{5} * {index} = {5*index}\")\n\t5 * 7 = 35\n\n```\n\nWhat we were doing earlier, was calling ```print()``` with a formatted string. Now we want to print this statement for different values of ```i```.\n\nHow can you do that?\n\nLet's start with a simple example.\n\n```py\n\t\u003e\u003e\u003e for i in range(1,11):\n\t...   print(f\"{i}\")\n\t...\n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\n\t8\n\t9\n\t10\n\n```\n\n```print(f\"{i}\")``` prints the value of i.\n\nNow, how do we get it to print ```5 * 1 = 5``` to  ```5 * 10 = 50```?\n\n```py\n\t\u003e\u003e\u003e for i in range(1,11):\n\t...   print(f\"5 * {i} = {5 * i}\")\n\t...\n\t5 * 1 = 5\n\t5 * 2 = 10\n\t5 * 3 = 15\n\t5 * 4 = 20\n\t5 * 5 = 25\n\t5 * 6 = 30\n\t5 * 7 = 35\n\t5 * 8 = 40\n\t5 * 9 = 45\n\t5 * 10 = 50\n\t\u003e\u003e\u003e 5 * 4 * 50\n\t1000\n\n```\n\n```print(f\"5 * {i} = {5 * i}\")``` prints a specific multiple of 5.\n\n### Step 15: Loops\n\nIn a previous step, we took a major step in programming. We wrote our first for loop with Python. In this step, let's try a few puzzles to understand the for loop even further.\n\nThe syntax of the for loop we looked at earlier was:\n\n```\n  for i in range(1, 10):\n\tprint(i)\n```\n\n\n#### Snippet-01:\n\nLet's say we write a ```for``` loop, but don't give a ```:``` after the ```range()``` method, to close the first line. What would happen?\n\n```py\n\t\u003e\u003e\u003e for i in range(1,10)\n\t  File \"\u003cstdin\u003e\", line 1\n\t    for i in range(1,10)\n\t                       ^\n\t\tSyntaxError: invalid syntax\n\n```\n\n Invalid syntax. A ```:``` is mandatory within the ```for``` loop syntax.\n\n Let's provide a `:` and in the next line, use `print(i)` without space before it (without indentation).\n\n```py\n\t\u003e\u003e\u003e for i in range(1,10):\n\t... print(i)\n\t  File \"\u003cstdin\u003e\", line 2\n\t    print(i)\n\t        ^\n\tIndentationError: expected an indented block\n\n```\n\nMost other programming languages use open brace ```{``` and closed brace ```}```  as delimiters in a ```for``` loop. However, Python uses indentation to identify which code is part of a ```for``` loop, and which is not. So if we are writing  the body of a ```for``` loop, we must use indentation, and leave atleast a single ```\u003cSPACE\u003e```.\n\n```py\n\t\u003e\u003e\u003e for i in range(1,10):\n\t...   print(i)\n\t...\n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\n\t8\n\t9\n\n```\n\nHow do we execute two lines of code as part of the ```for``` loop?\n\n```py\n\t\u003e\u003e\u003e for i in range(1,10):\n\t...  print(i)\n\t...  print(2*i)\n\t...\n\t1\n\t2\n\t2\n\t4\n\t3\n\t6\n\t4\n\t8\n\t5\n\t10\n\t6\n\t12\n\t7\n\t14\n\t8\n\t16\n\t9\n\t18\n\n```\n\nWe are indenting both statements with a space - `print(i)` and `print(2*i)`.\n\nWhen for loop has only one line of code, you can specify it right after the `:`\n\n```py\n\t\u003e\u003e\u003e for i in range(2,5): print(i)\n\t...\n\t2\n\t3\n\t4\n\n```\n\nHowever, this is not considered to be a good programming practice. Even though you may want to execute just one statement in a ```for``` loop, indentation on a new line is recommended.\n\nAnother best practice is to use four ```\u003cSPACE\u003e```s for indentation, instead of just two. This would give clear indentation of the code.\n\n```py\n\t\u003e\u003e\u003e for i in range(2,5):\n\t...     print(i)\n\t...\n\t2\n\t3\n\t4\n\n```\n\nAnybody who looks at the code immediately understands that this ```print()``` is part of the ```for``` loop.\n\nLet's say you only want to print the odd numbers till ```10```, which are ```1```, ```3```, ```5```, ```7``` and ```9```. The ```range()``` function offers an interesting option.\n\n```py\n\t\u003e\u003e\u003e for i in range (1,11,2):\n\t...   print(i)\n\t...\n\t1\n\t3\n\t5\n\t7\n\t9\n\n```\n\nIn ```for i in range(1, 11, 2)```, we pass in a third argument, called a *step*. After each iteration, the value of `i` is increment by `step`.\n\n#### Summary\n\nIn this step, we:\n\n* Looked at a few puzzles about the ```for``` loop, which lay emphasis on the following aspects of for:\n\t* The importance of syntax elements such as the colon\n\t* Indentation\n\t* Variations of the ```range()``` function\n\n### Step 16: Programming Exercise PE-BA-02\n\nIn the previous step, after initially exploring the Python ```for``` loop, we looked at a number of puzzles.\n\nIn this step, let's look at a few exercises.\n\n#### Exercises\n\n1. Print the even numbers up to 10. We would want to print 2 4 6 8 10, using a for loop.\n2. Print the first 10 numbers in reverse\n3. Print the first 10 even numbers in reverse\n4. Print the squares of the first 10 numbers\n5. Print the squares of the first 10 numbers, in reverse\n\n#### Solution 1\n\nInstead of starting with ```1```, we need to start with ```2```. Each time, ```i``` it would be incremented by ```2```, and ```2 4 6 8 and 10``` would be printed.\n\n```py\n\t\u003e\u003e\u003e for i in range (2,11,2):\n\t...   print(i)\n\t...\n\t2\n\t4\n\t6\n\t8\n\t10\n\n```\n\n#### Solution 2\n\n\nWe would want to print the numbers in reverse. Think about how you would do that using the ```range()``` function. We'd want go from ```10```, ```9```, ```8```, and so on up to ```1```.\n\n```py\n\t\u003e\u003e\u003e for i in range (10,0,-1):\n\t...   print(i)\n\t...\n\t10\n\t9\n\t8\n\t7\n\t6\n\t5\n\t4\n\t3\n\t2\n\t1\n\n```\n\nThe value to start with is ```10```. As we discussed earlier, the end value is exclusive. So to print from ```10``` to ```1```, we want to end one value  which is ```0```. ```range(10, 0)``` seems to be what we need.\n\nUsually these step value is positive, but we need to go backwards from ```10```. Hence, we would give a step value of ```-1```.\n\n\n#### Solution 3\n\nNext, we would want to print the squares of the first ```10``` numbers.\n\n```py\n\t\u003e\u003e\u003e for i in range (1,11):\n\t...   print(i * i)\n\t...\n\t1\n\t4\n\t9\n\t16\n\t25\n\t36\n\t49\n\t64\n\t81\n\t100\n\n```\n\n#### Solution 4\n\nLet's print the squares in the reverse order.\n\n```py\n\t\u003e\u003e\u003e for i in range (10,0,-1):\n\t...     print(i*i)\n\t...\n\t100\n\t81\n\t64\n\t49\n\t36\n\t25\n\t16\n\t9\n\t4\n\t1\n\n```\n\n#### Solution 5\n\nPrint the squares of the even numbers. How to do that?\n\n```py\n\t\u003e\u003e\u003e for i in range (10,0,-2):\n\t...     print(i*i)\n\t...\n\t100\n\t64\n\t36\n\t16\n\t4\n\n```\n\nThe key part is using a step of `-2`\n\nWe leave it as an exercise for you, to print squares of odd numbers.\n\n#### Summary\n\nIn this video, we:\n\t* Tried out a few exercises involving the for loop, by playing around with printing sequences of numbers.\n* Used the for loop to simplify the solution to the *PMT-Challenge* problem.\n\n### Step 17: Review: The Basics Of Python\n\nIt must have been a roller-coaster ride to solve the multiplication table challenge so far. If you're new to programming, there are a wide range of topics and concepts, that you would have learned during this small journey.\n\nLet's quickly revise the important concepts we have learned during this small journey.\n\n* ```1```, ```11```, ```5```, ... are all called literals because these are constant values. Their values don't really change.\n*Consider ```5 * 4 * 50```. This is an expression. ```*``` is an operator, and ```5```, ```4``` and ```50``` are operands.  \n* The name ```i``` in ```i = 1```, is called a variable. It can refer to different values, at different points in time.\n* ```range()``` and ```print()``` are in-built Python functions.\n* Every complete line of code is called statement. The specific statement ```print()```, is invoking a method. The other statement which we looked at earlier, was an assignment statement. ```index = index + 1``` would evaluate ```index + 1```, and have the ```index``` variable refer to that value.\n* The syntax of the ```for``` loop was very simple. ```for var in range(1, 10) : ...```, followed by statements you would want to execute in a loop, with indentation. For the sake of indentation we left four ```\u003cSPACE\u003e```s in front of each statement inside the ```for``` loop.\n\nSo that, in a nutshell, is what we have learned over the course of our first section.\n\n## Chapter 03 - Introducing Methods\n\nIn the last section, we introduced you to the basics of python. We learned those concepts by applying them to solve the *PMT-Challenge* problem. The code below is what we ended up with as we solved that chellenge.\n\n#### Snippet-01: Current Solution To *PMT-Challenge*\n\n```py\n\t\u003e\u003e\u003e for i in range (1,11):\n\t...   print(f\"8 * {i} = {8 * i}\")\n\n```\n\nIf we wanted to change the code to print the ```7``` table, we need to change the value ```7``` used in the for loop, to ```8```. It's simple, but still not as friendly as you would like.\n\n```py\n\t\u003e\u003e\u003e for i in range (1,11):\n\t...   print(f\"7 * {i} = {7 * i}\")\n```\n\nTo print a ```7``` table, it would be awesome if could say ```print_multiplication_table```, and give a value of 7 beside it, and it would do the rest:\n\n```py\n\t\u003e\u003e\u003e print_multiplication_table(7)\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'print_multiplication_table' is not defined\n\t\u003e\u003e\u003e print_multiplication_table(8)\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'print_multiplication_table' is not defined\n\n```\n\nSimilarly, ```print_multiplication_table(8)```, could print the multiplication table for ```8```!\n\nTo be able to do this, we need to create a **method**, or a **function**. Creating a method makes the code *reusable*, and we can invoke that method very easily by passing *arguments*.\n\nIn this section, we take an in-depth look at methods.\n\n### Step 01: Defining Your First Method\n\nMethods are very important building blocks in Python programming. In this step, we will create a simple method that prints ```\"Hello World\"```, twice.\n\n#### Snippet-01:\n\nWhen we talk about a method, we need to give it a name. We are already using an in-built Python method here, which is ```print()```.\n\n```py\n\t\u003e\u003e\u003e print(\"Hello World\")\n\tHello World\n\t\u003e\u003e\u003e print(\"Hello World\")\n\tHello World\n\n```\n\n Similar to that, we need to give a name to our body of code. Let's say the name is ```print_hello_world_twice```.\n\nThe syntax to create a method in Python is straightforward:\n* At the start, use the keyword ```def``` followed by a space.\n* Followed by name of the method - `print_hello_world_twice`.\n* Add a pair of parenthesis: ```()```.  \n* This is followed by a colon ```:``` (similar to what we used in a  ```for``` loop).\n\n\n```py\n\t\u003e\u003e\u003e def print_hello_world_twice():\n\t...     print(\"Hello World\")\n\t...     print(\"Hello World\")\n\t...\n```\nAll statements in a method should be indented. The two `print(\"Hello World\")` are indented. So, they are part of the method body.\n\n```print_hello_world_twice()``` defines a method, and it has certain code inside its body.\n\nHow do we call this method? Is it sufficient to say ```print_hello_world_twice```?\n\n```py\n\t\u003e\u003e\u003e print_hello_world_twice\n\t\u003cfunction print_hello_world_twice at 0x10a71ef28\u003e\n\n```\n\nPython Shell says, there's a function defined with that specific name.\n\nHow do we execute a method? Very simple! Add a pair of parentheses to the name, ```()```!\n\n```py\n\t\u003e\u003e\u003e print_hello_world_twice()\n\tHello World\n\tHello World\n\t\u003e\u003e\u003e print_hello_world_twice()\n\tHello World\n\tHello World\n\n```\n\n Now, we are able to run the method.\n\n#### Summary\n\nIn this step, we:\n\n* Learned we can define our own methods in the code we write\n* Understood how to define a method, and all its syntax elements\n* Saw how we can invoke a method we write\n\n### Step 02: Programming Exercise PE-MD-01\n\nWe will now leave you with two exercises, based on what we have learned about methods so far.\n\n#### Exercises\n\n1. Write a method called ```print_hello_world_thrice()```. It should print ```\"Hello World\"``` thrice to the output. Define this method, and also invoke it.\n\n2. Write and execute a method, that prints four statements:\n\t1. \"I have created my first variable.\"\n\t2. \"I've created in my first loop.\"\n\t3. \"I've created my first method.\"\n\t4. \"I am excited to learn Python.\"\n\tYou need to print these four statements on four consecutive lines.\n\n#### Solutions\n\n#### Solution 1\n\n```py\n\t\u003e\u003e\u003e def print_hello_world_thrice():\n\t... \tprint(\"Hello World\")\n\t...     print(\"Hello World\")\n\t...     print(\"Hello World\")\n\t...\n\t\u003e\u003e\u003e print_hello_world_thrice()\n\tHello World\n\tHello World\n\tHello World\n\n```\n\n#### Solution 2\n\n```py\n\t\u003e\u003e\u003e def print_your_progress():\n\t...     print(\"Statement 1\")\n\t...     print(\"Statement 2\")\n\t...     print(\"Statement 3\")\n\t...     print(\"Statement 4\")\n\t...\n\t\u003e\u003e\u003e print_your_progress()\n\tStatement 1\n\tStatement 2\n\tStatement 3\n\tStatement 4\n\n```\n\n```py\n\tdef print_your_progress():\n\t\tprint(\"Statement 1\")\n\t\tprint(\"Statement 2\")\n\t\tprint(\"Statement 3\")\n\t\tprint(\"Statement 4\")\n\n```\n\nFor convenience, we have changed the exact text we need to print. Call this method with the syntax ```print_your_progress()```, and you're able to execute its code.\n\nNow try another exercise. We want to print ```\"Statement 1\"```,  ```\"Statement 2\"```, ```\"Statement 3\"``` and ```\"Statement 4\"``` on different lines, using just one print statement. How can you do that?\n\n```py\n\t\u003e\u003e\u003e def print_your_progress():\n\t...     print(\"Statement 1\\nStatement 2\\nStatement 3\\nStatement 4\")\n\t...\n\t\u003e\u003e\u003e print_your_progress()\n\tStatement 1\n\tStatement 2\n\tStatement 3\n\tStatement 4\n\n```\n\nWe are using the newline character `\\n`.\n\nLet's look at the difference between defining and executing a method.\n\nWhen we are writing a method definition, we are writing the code as part of its body.  It has a specific syntax, and starts with the ```def``` keyword.\n\nA definition by itself cannot cause the code in its body to be executed.\n\n```print_your_progress()``` represents a method call. The code inside the method is executed.\n\n#### Summary\n\nIn this step, we:\n\n* Implemented solutions to a few exercises that test our understanding of Python methods. We touched concepts such as:\n\t* Defining a method body\n\t* The way to invoke a method, to run its code\n\t* The difference between the two\n\n### Step 03: Passing Parameters To Methods\n\nIn the previous step,we created methods. We defined ```print_hello_world_twice()```, and this printed ```\"Hello World\"``` twice. In this step, let's talk about *method arguments*, or *parameters*.\n\n#### Snippet-01:\n\n```py\n\n\t\u003e\u003e\u003e print_hello_world_twice()\n\tHello World\n\tHello World\n\t\u003e\u003e\u003e print_hello_world_thrice()\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nEarlier, we wrote code for ```print_hello_world_thrice()```, which prints the message three times.\n\nLet's say you want to print it five times. You would need to write another method that does what you need. Doesn't that seem monotonous?\n\nInstead of that, Won't it be great if I can call the method by the same name, say ```print_hello_world(5)```, and it would print \"Hello World\" five times?\n\nThe ```5``` which we are passing here is called an **argument**.\n\nHow do we define our method to accept this argument?\n\nLet's call our argument ```no_of_times```. If you have any experience with other programming languages, they generally need you to specify the parameter type. Something like `This parameter is an integer/float/string, or other types`. But Python does not require parameter type.\n\n```py\n\t\u003e\u003e\u003e def print_hello_world(no_of_times):\n\t...    print(\"Hello World\")\n\t...    print(no_of_times)\n\t...\n\n```\n\nAlthough we are not doing exactly what we set out to, let's see what would happen. What would happen if we say ```print_hello_world()``` ?\n\n```py\n\n\t\u003e\u003e\u003e print_hello_world()\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tTypeError: print_hello_world() missing 1 required positional argument: 'no_of_times'\n\n```\n\nError! Something like \"Hey, you have created ```print_hello_world``` with a parameter, but not passing anything in here! Go ahead and pass a value\". Let's pass in a value, such as ```5```.\n\n```py\n\t\u003e\u003e\u003e print_hello_world(5)\n\tHello World\n\t5\n\t\u003e\u003e\u003e print_hello_world(10)\n\tHello World\n\t10\n\t\u003e\u003e\u003e print_hello_world(100)\n\tHello World\n\t100\n\n```\n\nWith ```print_hello_world(5)```, you can see ```\"Hello World\"``` and ```5``` being printed. We are now able to define this method to accept a value, and print that value by invoking it. You can pass in any value, such as```10```, ```100```, or others.\n\nNow think of a different solution for this method, where you don't repeat the same piece of code to print ```\"Hello World\"```. Consider  ```print_hello_world(5)```, it should still print ```\"Hello World\"``` ```5``` times. How do you do that?\n\nThink about using something along the lines of a loop.\n\n#### Snippet-02:\n\nFor now, what we are doing is we are printing ```\"Hello World\"``` ```10``` times.\n\n```py\n\t\u003e\u003e\u003e def print_hello_world(no_of_times):\n\t...    for i in range(1,10):\n\t...       print(\"Hello World\")\n\t...\n\n\t\u003e\u003e\u003e print_hello_world(5)\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\nOur method call ```print_hello_world(5)``` now prints ```\"Hello World\"``` ```10``` times.\n\nHowever  just print the message ```5``` times. We need to make use of the parameter ```no_of_times``` inside the ```for``` loop as well.\n\n```py\n\t\u003e\u003e\u003e def print_hello_world(no_of_times):\n\t...    for i in range(1,no_of_times):\n\t...       print(\"Hello World\")\n\t...\n\n\t\u003e\u003e\u003e print_hello_world(5)\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nNow let's execute the method again. You can see that it's printing ```4``` times only.\n\nWhy is it not printing ```5``` times?\n\nThat's because ```no_of_times``` as a second parameter to ```range()``` is exclusive.  \n\n```py\n\t\u003e\u003e\u003e def print_hello_world(no_of_times):\n\t...    for i in range(1,no_of_times+1):\n\t...       print(\"Hello World\")\n\t...\n\t\u003e\u003e\u003e print_hello_world(5)\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nGreat, it's now printing the message ```5``` times!\n\n```py\n\t\u003e\u003e\u003e print_hello_world(7)\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nIf you pass a different argument like ```7```, the message is displayed ```7``` times.\n\nSomething you need to always be cautious about in Python, is the indentation. Over here, the ```for``` loop is part of the method body. So we have extra  indentation for it. The print is part of the ```for``` loop body. So guess what, even more indentation for that code.\n\n#### Summary\n\nIn this step, we:\n\n* Learned how to pass arguments to a method\n* Understood that the method definition needs to have parameters coded in\n* Observed that arguments passed during a method call can be accessed inside a methods body\n\n### Step 04: Classroom Exercise CE-MD-01\n\nIn this step, Let's look at a few exercises related to the method parameter.\n\n#### Exercises\n\n1. Write a method called ```print_numbers()```, that would print all successive integers from ```1``` to ```n```.\n\n2. The second one is to write a method called ```print_squares_of_numbers()```, that prints squares of all successive integers from ```1``` to ```n```.\n\n#### Solutions\n\n#### Solution 1\n\n```py\n\t\u003e\u003e\u003e def print_numbers(n):\n\t...    for i in range(1, n+1):\n\t...       print(i)\n\t...\n\t\u003e\u003e\u003e print_numbers(5)\n\t1\n\t2\n\t3\n\t4\n\t5\n\t\u003e\u003e\u003e\n\n```\n\nIf you are programming in other languages such as Java, you are used to naming methods in this way: ```printNumbers()```. This convention is popularly known as \"Camel Case\".\n\nThat's NOT how Python programmers name their methods. Pythonic way is to use underscore  ```_``` to separate words in the method name, as in ```print_numbers()```.\n\n#### Solution 2\n\nLet's define ```print_squares_of_numbers()```. This would be very similar to ```print_numbers()```, working with the same range. Only, we need to say ```print(i*i)``` .\n\n```py\n\t\u003e\u003e\u003e def print_squares_of_numbers(n):\n\t...    for i in range(1, n+1):\n\t...       print(i*i)\n\t...\n\t\u003e\u003e\u003e print_squares_of_numbers(5)\n\t1\n\t4\n\t9\n\t16\n\t25\n\n```\n\n\nHow is a parameter different from an argument?\n\n* Inside the definition of the method, the name within parentheses is referred to as a **parameter**. In our recent exercise, ```n``` is a parameter, because it's used in the definition of ```print_squares_of_numbers```.\n* When you are passing a value to a method during a method call, say ```5```, that value is called an **argument**.  \n* Don't worry too much about it. Just follow this convention for now:\n\t* In the method call, call it an *argument*.\n\t* In a method definition, call it a *parameter*.\n\n#### Summary\n\nIn this step, we looked at a few simple exercises related to passing method arguments\n\n### Step 05: Methods With Multiple Parameters\n\nIn this step, let's look at creating a method with multiple parameters.\n\n#### Snippet-01:\n\n`print_hello_world` accepts one parameter and prints \"Hello World\" the specified number of times.\n\n```py\n\t\u003e\u003e\u003e def print_hello_world(no_of_times):\n\t...    for i in range(1,no_of_times+1):\n\t...       print(\"Hello World\")\n\t...\n\n```\n\n Let's say we want to print another piece of text ```Welcome To Python```, a specified number of times. How do you do that?\n\n  You can always create another method similar to the first one, such as  ```print_welcome_to_python(no_of_times)``` and print the necessary text inside.\n\n  However, is that what a good programmer does?\n\n  A good programmer tries to create a more generic solution.\n\n```py\n\t\u003e\u003e\u003e def print_string(str, no_of_times):\n\t...    for i in range(1,no_of_times+1):\n\t...       print(str)\n\t...\n\t\u003e\u003e\u003e print_string(\"Hello World\", 3)\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nThe good programmer that you are, you created a new method called ```print_string(str, no_of_times)``` accepting a text parameter, in addition to ```no_of_times```.\n\nSyntax rules for method parameters are quite strict. If we say ```print_string(\"Welcome to Python\")``` and run it, we get an error! Python Shell says: \"I need ```no_of_times``` to be present in here\".\n\n```py\n\t\u003e\u003e\u003e print_string(\"Welcome to Python\")\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tTypeError: print_string() missing 1 required positional argument: 'no_of_times'\n\n```\n\nLet's say you want to assign default values for ```str``` and ```no_of_times``` in ```print_string()```. By default, we want to always print ```\"Hello World\"```, and that too ```5``` times.\n\nThe Python language makes this very easy. ```def print_string(str = \"Hello World\", no_of_times=5)```. The rest of the method remains the same.\n\n```py\n\t\u003e\u003e\u003e def print_string(str=\"Hello World\", no_of_times=5):\n\t...    for i in range(1,no_of_times+1):\n\t...       print(str)\n\t...\n\n```\nNow you can call ```print_string()```, and ```\"Hello World\"``` is displayed ```5``` times.\n\n```py\n\t\u003e\u003e\u003e print_string()\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nIf it's ```print_string(\"Welcome To Python\")```, what does it do? It prints ```\"Welcome To Python\"```, ```5``` times.\n\n```py\n\t\u003e\u003e\u003e print_string(\"Welcome to Python\")\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\n```\n\nConsider  ```print_string(\"Welcome to Python\", 8)```, it would print that string ```8``` times.  \n\n```py\n\t\u003e\u003e\u003e print_string(\"Welcome to Python\", 8)\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\tWelcome to Python\n\n```\n\nIsn't that cool!\n\n#### Summary\n\nIn this step, we:\n\n* Looked at how to pass multiple parameters to a method, starting with two arguments\n* Learned how you can define default values for those parameters\n* Observed we could pass default arguments for none, some or all of those parameters\n\n### Step 06: Back To Multiplication Table - Using Methods\n\nLet's get back to our original goal, of why we needed methods. We wanted to create a multiplication table for a number, and observed that each time we needed to we needed change that number, we were forced to make a change in the code. This is not something we liked, and that's why we started investigating how methods can be used.\n\nIn this step, Let's try our hand at creating a multiplication table method.\n\n#### Snippet-01:\n\n```py\n\t\u003e\u003e\u003e for i in range (1,11):\n\t...    print(f\"7 * {i} = {7 * i}\")\n\n```\n\nLet's define a method called ```print_multiplication_table()```, and pass in a parameter to it.\n```py\n\t\u003e\u003e\u003e def print_multiplication_table(table):\n\t...    for i in range(1,11):\n\t...       print(f\"{table} * {i} = {table * i}\")\n\t...\n\t\u003e\u003e\u003e print_multiplication_table(7)\n\t7 * 1 = 7\n\t7 * 2 = 14\n\t7 * 3 = 21\n\t7 * 4 = 28\n\t7 * 5 = 35\n\t7 * 6 = 42\n\t7 * 7 = 49\n\t7 * 8 = 56\n\t7 * 9 = 63\n\t7 * 10 = 70\n\n```\n\nNow you have the entire multiplication table for ```7```.\n\nYou can then call ```print_multiplication_table()``` with arguments ```8```, ```9```,and so on, by simply changing the ```table``` arguemnt value.\n\nWe now want to create even better ```print_multiplication_table()``` method.\n\nWe want to control the start point, as well as the end point, in the call to ```range()```. We want to  say ```print_multiplication_table(7, 1, 6)```, to print the ```7``` table with entries from ```1``` to ```6```. How can you do that?\n\n```py\n\t\u003e\u003e\u003e def print_multiplication_table(table, start, end):\n\t...    for i in range(start, end+1):\n\t...       print(f\"{table} * {i} = {table * i}\")\n\t...\n\t\u003e\u003e\u003e print_multiplication_table(7, 1 , 6)\n\t7 * 1 = 7\n\t7 * 2 = 14\n\t7 * 3 = 21\n\t7 * 4 = 28\n\t7 * 5 = 35\n\t7 * 6 = 42\n\n```\n\nSimple! Define those range limits as additional parameters!\n\nThe other thing we can obviously do, is have default values for the ```start```, and the ```end```.\n\n```py\n\t\u003e\u003e\u003e def print_multiplication_table(table, start=1, end=10):\n\t...    for i in range(start, end+1):\n\t...       print(f\"{table} * {i} = {table * i}\")\n\t...\n\n\t\u003e\u003e\u003e print_multiplication_table(7)\n\t7 * 1 = 7\n\t7 * 2 = 14\n\t7 * 3 = 21\n\t7 * 4 = 28\n\t7 * 5 = 35\n\t7 * 6 = 42\n\t7 * 7 = 49\n\t7 * 8 = 56\n\t7 * 9 = 63\n\t7 * 10 = 70\n\n```\n\nCalling ```print_multiplication_table(7)``` would give us entries from ```7 * 1 = 7``` to ```7 * 10 = 70```.\n\nNow you can actually send out this method, to your friends, who would find it easy to use, and cool!\n\n#### Summary\n\nIn this step, we:\n\n* Learned how to define a method to print the multiplication table for a  number\n* Looked at how to enhance this method to make table printing more flexible\n* Further enhanced that method to accept default arguments while printing a table\n\n### Step 07: Indentation Is King\n\nIn Python, indentation denote blocks of code. So if you want to put something in a ```for``` loop, or outside it, proper indentation would be sufficient. In this step, let's explore indentation in depth. Let's start by creating a simple method.\n\n#### Snippet-01:\n\n```\n\n\t\u003e\u003e\u003e def method_to_understand_indentation():\n\t...     for i in range(1,11) :\n\t...        print(i)\n\t...\n\t\u003e\u003e\u003e method_to_understand_indentation()\n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\n\t8\n\t9\n\t10\n\n```\n\nConsider the code below: `print(5)` is indented at the same level as `for loop`.\n\n```py\n\t\u003e\u003e\u003e def method_to_understand_indentation():\n\t...     for i in range(1,11) :\n\t...        print(i)\n\t...     print(5)\n\t...\n```\n\nYou can see that `print(5)` is called only once. It is not part of the `for loop`.\n\n```\n\t\u003e\u003e\u003e method_to_understand_indentation()\n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\n\t8\n\t9\n\t10\n\t5\n\n```\n\nLet's change the code in this method a bit. `print(5)` is indented the same way as `print(i)`\n\n```py\n\t\u003e\u003e\u003e def method_to_understand_indentation():\n\t...     for i in range(1,11) :\n\t...        print(i)\n\t...        print(5)\n\t...\n```\n\n`print(5)` is part of the for loop. It is executed 10 times.\n\n```py\n\t\u003e\u003e\u003e method_to_understand_indentation()\n\t1\n\t5\n\t2\n\t5\n\t3\n\t5\n\t4\n\t5\n\t5\n\t5\n\t6\n\t5\n\t7\n\t5\n\t8\n\t5\n\t9\n\t5\n\t10\n\t5\n\n```\n\nWhether we're talking about loops, methods or conditionals, proper indentation is very important in Python.\n\nWe indicate a block of code, by having all lines of that block at the same indentation level. There are no specific delimiters like for instance a pair of braces ```{...}```, as in other programming languages.\n\n#### Summary\n\nIn this step, we:\n\n* Ran through a few examples to see how indentation works in Python\n\n### Step 08: Puzzles on Methods - Named Parameters\n\nIn this step, let's look at a variety of puzzles related to methods.\n\n#### Snippet-01:\n\nConsider the following method: I would want to print the default string 6 times. How do we do it?\n\n```py\n\t\u003e\u003e\u003e def print_string(str=\"Hello World\", no_of_times=5):\n\t...     for i in range(1,no_of_times+1):\n\t...        print(str)\n\t...\n\t\u003e\u003e\u003e print_string()\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\n\nWill it work if we call the method as in: ```print_string(6)```?\n\n```py\n\t\u003e\u003e\u003e print_string(6)\n\t6\n\t6\n\t6\n\t6\n\t6\n\n```\n\n```6``` is passed as the first parameter. ```6``` is matched to ```str```, and the method prints ```6``` the default number of times, which is ```5```.\n\n to default to ```\"Hello World\"```, and print it ```6``` times.\n\nYou can do this in Python by using **named parameters**. During the method call, you can specify ```no_of_times = 6```. **```no_of_times```** is a named parameter.\n\n\u003e There is no provision of doing something like this, in other languages like Java.\n\nCall it as ```print_string(no_of_times=6)```:\n\n```py\n\t\u003e\u003e\u003e print_string(no_of_times=6)\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\tHello World\n\n```\n```str``` gets a default value, and ```\"Hello World\"``` is printed ```6``` times.\n\nNamed parameters are very useful, when a method has a number of parameters, and you would want to make it very clear which parameter you're passing a value for.\n\nLet's call ```print_string(7, 8)```. what happens?\n\n```py\n\t\u003e\u003e\u003e print_string(7, 8)\n\t7\n\t7\n\t7\n\t7\n\t7\n\t7\n\t7\n\t7\n\n```\n\nYou would see that ```7``` is printed ```8``` times.\n\nSince ```print()``` method is quite flexible, you can pass a number as the first argument. You can even pass a ```float```.\n\n\n```py\n\t\u003e\u003e\u003e print_string(7.5, 8)\n\t7.5\n\t7.5\n\t7.5\n\t7.5\n\t7.5\n\t7.5\n\t7.5\n\t7.5\n\n```\n\nWhat would be the result of this - ```print_string(7.5, \"eight\")```?\n\n```py\n\t\u003e\u003e\u003e print_string(7.5, \"eight\")\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\t  File \"\u003cstdin\u003e\", line 2, in print_string\n\tTypeError: must be str, not int\n```\n\nNote how ```no_of_times``` is used inside the method... as an argument to ```range()```. ```range()``` only accepts integers, nothing else. When you run the code with ```print_string(7.5, \"eight\")```, we get an error.\n\nIt says: `TypeError: ```no_of_times``` must be ```int```, not string`.\n\n\nA simple rule of thumb is, if you have a parameter, you can pass any type of data to it. That could be an integer, a floating point value a string, or a boolean value. The Python language does not check for the type of a parameter. However, Python will throw an error if the function which is using that parameter, expects it to be of a specific type. The ```range()``` function expects that the ```no_of_times``` is an integer value.\n\n#### Snippet-02:\n\nThe last thing which we would be looking at, is method naming conventions. We named our methods in a consistent way: ```print_string```, ```print_multiplication_table```, and the like.\n\nThis is exactly the format which most Python developers use, to name their methods.\n\nConvention is to use underscore to separate words in a name.\n\nHowever, there are a few rules for naming a method:\n\nOne of the important rules is also related to variable names. We observed that a variable name cannot start with  a number.\n\n```py\n\t\u003e\u003e\u003e def 1_print():\n\t  File \"\u003cstdin\u003e\", line 1\n\t    def 1_print():\n\t         ^\n\tSyntaxError: invalid token\n\n```\n\nSimilarly, ```1_print``` will not be accepted as a method name.\n\n* You can start a name with an alphabet, or with an underscore.\n* From the second character onward, you are allowed to use numeric symbols.\n\nMethods and variables cannot be named using Python keywords.\n\nNow, what is a keyword? For example, when we talked about ```for``` loop, as in:\n\n\t```for i in range(1, 11): print(i)```...\n\n* **```for```** is a keyword\n* **```in```** is a keyword\n* **```def```** is a keyword.\n\nLater we will look at a few other keywords, such as **```while```**, **```return```**, **```if```**, **```else```**, **```elif```**, and many more.\n\n```py\n\t\u003e\u003e\u003e def def():\n\t  File \"\u003cstdin\u003e\", line 1\n\t    def def():\n\t          ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e def in():\n\t  File \"\u003cstdin\u003e\", line 1\n\t    def in():\n\t         ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e def for():\n\t  File \"\u003cstdin\u003e\", line 1\n\t    def for():\n\t          ^\n\tSyntaxError: invalid syntax\n\n```\n\n\n#### Summary\n\nIn this step, we:\n\n* Were introduced to the concept of named parameters\n* Explored the typical naming rules and conventions for methods in Python\n* Observed that reserved keywords cannot be used to name variables or methods\n\n### Step 09: Methods - Return Values\n\nLet's try and understand the importance of return values from a method. We will learn how to return a value from a method.\n\n#### Snippet-01:\n\nLet's name our method as ```product_of_two_numbers()```, and let's have parameters ```a``` and ```b``` that it accepts:\n\n```py\n\t\u003e\u003e\u003e def product_of_two_numbers(a,b):\n\t...     print(a * b)\n\t...\n\t\u003e\u003e\u003e product_of_two_numbers(1,2)\n\t2\n\n```\n\nCan we take the product of these two numbers into a variable, and use it in other code, in the same program?\n\nSuppose we say a ```product = product_of_two_numbers(1,2)```, is this allowed?\n\nLet's run this code, and see what's stored in ```product```.\n```py\n\t\u003e\u003e\u003e product = product_of_two_numbers(1,2)\n\t2\n\t\u003e\u003e\u003e product\n\n```\n\nIt's empty.\n\nThe ```product_of_two_numbers()``` method is not really returning anything back, to be used elsewhere.\n\nHave a look at some of the built-in Python functions, such as ```max()``` for example.\n\n```py\n\t\u003e\u003e\u003e max(1,2,3)\n\t3\n\t\u003e\u003e\u003e max(1,2,3,4)\n\t4\n\t\u003e\u003e\u003e maximum = max(1,2,3,4)\n\t\u003e\u003e\u003e maximum\n\t4\n\t\u003e\u003e\u003e maximum * 5\n\t20\n\n```\n\nIf I call ```max()``` with four parameters, as in ```maximum = max(1,2,3,4)```, the value ```4``` gets stored in maximum.\n\nLater on in the code that follows, we can say ```maximum * 5```,  or we can print the value of ```maximum```, or a similar calculation. This gives our programs a lot more flexibility.\n\nSo instead of just printing ```a*b```, if this function could return a value, that would be quite useful.\n\n```py\n\t\u003e\u003e\u003e def product_of_two_numbers(a,b):\n\t...      product = a * b;\n\t...      return product\n\t...\n\t\u003e\u003e\u003e product_of_two_numbers(2,3)\n\t6\n\n```\n\nWe are creating a variable ```product``` and doing a ```return product```.\n\nLets run ```product_result = product_of_two_numbers(2, 3)```\n\n```py\n\t\u003e\u003e\u003e product_result = product_of_two_numbers(2,3)\n\t\u003e\u003e\u003e product_result\n\t6\n\t\u003e\u003e\u003e product_result * 10\n\t60\n\n```\n\nYou can see how simple it is to return values from a method!\n\n#### Summary\n\nIn this step, we:\n\n* Learned how to return values from inside a method\n* Observed how we can store the values returned by a method call\n\n### Step 10: Programming Exercise PE-MD-02\n\nIn this step let's look at a couple of exercises about returning values from methods.\n\n#### Exercises\n\n1. Write a method to return the sum of three integers.\n\n2. Write a method which takes as input two integers, representing two angles of a triangle,  and computes the third angle.\n\nHint: The sum of the angles in a triangle is ```180``` degrees. So if I am passing ```50``` and ```50```, ```50``` plus ```50``` is ```100```. So some of three angles should be ```180```, so the third angle will be ```180 - 100```, which is ```80```.\n\n#### Solution 1\n\n```py\n\t\u003e\u003e\u003edef sum_of_three_numbers(a, b, c):\n\t...     sum = a + b + c\n\t...     return sum\n\t...\n\n\t\u003e\u003e\u003e sum_of_three_numbers(1,2,3)\n\t6\n\t\u003e\u003e\u003e something = sum_of_three_numbers(1,2,3)\n\t\u003e\u003e\u003e something * 5\n\t30\n\n```\nThe shorter way of doing that would have been to have a temporary variable called instead of ```sum```. We could directly ```return a + b + c```.\n\n```py\n\t\u003e\u003e\u003e def sum_of_three_numbers(a, b, c):\n\t...     return a + b + c\n\t...\n\t\u003e\u003e\u003e something = sum_of_three_numbers(1,2,3)\n\t\u003e\u003e\u003e something * 5\n\t30\n\n```\n\nIn methods, you can use `return expression` as well. That `expression` gets evaluated, and the value gets returned back. You'd see that the result remains the same.\n\n#### Solution 2\n\nThe second is to write a method to take two integers, representing two angles of a triangle, and compute the third one.\n\n```py\n\t\u003e\u003e\u003e def calculate_third_angle(first, second) :\n\t...     return 180 - ( first + second )\n\t...\n\t\u003e\u003e\u003e calculate_third_angle(50, 20)\n\t110\n\n```\n\nIn your programming career, you would be writing a number of methods. It's very important that you are comfortable  doing so. Most of the methods that you write would return values back.\n\nThat's the reason why we're creating a lot of examples involving method calls.\n\n#### Summary\n\nIn this step, we:\n\n* Looked at a couple of exercises related to returning values from methods\n* Observed that returning expressions avoids creating unnecessary variables, and shortens method definitions\n\n\n## Chapter 04 - Introduction To Python Platform\n\nUntil now we had been using Python Shell to execute all our code.\n\nIn the real world, we'll be write Python code in a variety of scripts. Before we would go into an IDE and use the IDE to write the script, we thought it would be useful for us to understand how you can write Python code without the benefit of an IDE.\n\nThis would also help us understand the Python environment, in-depth.\n\nIn the next few steps, we'll be looking at how to create simple Python scripts, using any text editor of your choice. Use Notepad, Notepad++. Editpad, or whichever text editing software you are comfortable with. We'll see what involved in executing the program, and what's happening in the background.\n\n\n### Step 01 - Writing and Executing Python Shell Programs\n\nLet's get started with creating a simple script file.\n\nWe want to type in a simple Python script, or a piece of Python code, such as ```print(\"Hello world\")```. Does it get any simpler than this?\n\nWe'll save this into any folder on our hard disk, with a name 'first.py' .\n\n***first.py***\n\n```py\nprint(\"Hello world\")\n```\n\nThe '.py' is not really mandatory, but typically all python files end with a '.py' extension.\n\nHere's how you can run it:\n- Launch your terminal, or command prompt\n- 'cd' to the folder where this python script file is saved\n- execute the command `python first.py`\n\nYou will see that `Hello World` will be printed.\n\nIf you are familiar with other programming languages, you would need a class, need to put the code in that class, and similar stuff.\n\nWhile Python supports Object Oriented Programming, is not mandatory to create a class.\n\nIt's almost as if you're typing commands, starting from the line one! That's why we call it a python script.\n\n\n#### Summary\n\nIn this small step, we tried to create a simple python script, and we ran it from the command line. All we needed to do, was use the same command we use to launch up the python shell, and followed it up with a name of the file. We created a file called first.py, executed that, and were able to see the output on the console.\n\nAs an exercise, try and add a few more methods and try to run those methods as well, as part of this script.\n\n### Step 02 - Python virtual machine and bytecode\n\nIn this step, let's try and understand what's happening in the background.\n\nWe wrote a simple piece of code using a text editor. We created a file named first.py, and all we did was: `python3 first.py`. If you look at other languages like Java for example, there is a separate compilation phase and then an execution phase. But with Python, just this command does both compilation and execution.\n\nWe saw that, as soon as we make a change and we run `python3 first.py` , the change is compiled and executed as well!\n\nIn Python, there is an intermediate format called **Python byte code**. Code is first compiled to bytecode, and then executed on the **Python virtual machine**.\n\nWhen we installed Python, we installed both the python compiler and interpreter, as well as the virtual machine.\n\nIn Python, `bytecode` is not standardized. Different implementations of Python have different byte code. There are about 80 Python implementations, like CPython and Jython.\n- CPython is a Python implementation in C language.\n- Jython is a Python implementation in Java language. The bytecode which Jython uses is actually Java bytecode, and you can run it on the Java virtual machine.\n\nPython leaves a lot of flexibility to the implementations of Python. They have the flexibility to choose the bytecode, and to choose the virtual machine that is compatible. The bytecode is tied to the specific virtual machine you are using. Therefore, if you're using CPython to compile the bytecode, you'll not be able to use Jython to run it.\n\nYou should make sure, that whatever implementation you are using to compile, is the same one you're using to run the code as well.\n\n#### Summary\n\nA lot of this sounds like boring theory. Don't worry about it. As a beginner, this might not be very important for you right now.\n\nIt's very important for you to understand the process. What's happening is you were writing Python code, and when you ran the command `python3 first.py`, it is both compiled and executed. An intermediate format called bytecode is created, which is not really standardized in Python. The bytecode is executed in a Python virtual machine.\n\nThe idea behind this quick section, is to give you a little bit of background on what's happening behind the scenes. I'll see you in the next section. Until then, bye-bye!\n\n## Chapter 05 - Introduction To PyCharm\n\nLet's start using the IDE PyCharm to write our Python Code\n\nHere are recommended videos to watch\n- [Installing PyCharm](https://www.youtube.com/watch?v=SZUNUB6nz3g)\n- [Write and Execute a Python File with PyCharm](https://www.youtube.com/watch?v=JLfd9LOdu_U)\n\n\n### Step 01 - Installing and Introduction to PyCharm\n\nIn this quick step, we'll help you install PyCharm.\n\nHere's the video guide for this step\n- [Installing PyCharm](https://www.youtube.com/watch?v=SZUNUB6nz3g)\n\nGo to Google and type in \"PyCharm Community Edition Download\". Click the link which comes up first: https://www.jetbrains.com/pycharm/download.\n\nYou'll go to a page where you can choose the operating system: whether you are on Windows, Mac, or Linux.\n\nOnce you choose that, you can download the appropriate community version.\n\nOn the right hand side, you'll see a community version, and you can click the download link, to start the download.\n\nIf you are having a problem, you can also use the direct link to download.\n\nOnce you download PyCharm, all you need to do is double-click the package which is downloaded. Follow the instructions, and you can continue with the defaults, until you completely install PyCharm.\n\nWhen you launch PyCharm for the first time, it should ask you for a theme, where you can choose the default.\n\nYou're all set to go ahead with the next step in the course.\n\nPycharm is an awesome IDE, and I'm sure you learn a lot about it.\n\n\n### Step 02 - Write and Execute a Python File with PyCharm\n\nIn this step, let's launch up the PyCharm IDE, and create our first Python project with a Python script. We want to be able to launch a Python script by the end of this step.\n\nHere's the video guide for this step\n- [Write and Execute a Python File with PyCharm](https://www.youtube.com/watch?v=JLfd9LOdu_U)\n\nLaunch the Pycharm IDE. You'll see that it takes a little while to launch the first time, and then brings up a welcome screen.\n\nWe would want to create a number of Python files. All these files will be in a project. You can think of our project as a collection of Python scripts, or modules.\n\nTo get started, let's create a new project by clicking 'create new project'. Let's name it -  '01-first-python-project'.\n\nRight now there are no files in the project.\n\nLet's create our first Python file, using the IDE.\n\nThe way you can do that is by saying 'right-click' -\u003e 'new' -\u003e 'Python file', and then we'll give this a name of 'hello_world', and click OK.\n\nNow you can go ahead and write your first Python program. Let's write some simple code, like ```print(\"Hello World\")```, and save it.\n\nYou can do a right-click here, and say 'Run hello_world'.\n\nA small window comes up below, which shows the output. It says ```'Hello World'```.\n\n\n### Step 03 - Execise - Write Multiplication Table Method with PyCharm\n\nLet's start with a simple exercise. We created the multiplication table method in the Python Shell. What we do now, is we'll create the same thing but in a Python file of its own.\n\n## Chapter 06 - Introducing Data Types and Conditionals\n\nWelcome to this section, where we will talk about numeric data types, and conditional program execution. After looking at the numeric and boolean data types, we will turn our attention to executing code, based on logical conditions.\n\n### Step 01: Numeric Data Types\n\nIn previous sections, we created variables of this kind: ```number = 5``` , ```value = 2.5```, etc. The ```5``` here is an integer, and integers represent numbers, such as ```1```, ```2```, ```6```, ```-1``` and ```-2```. In Python, the ```class``` for this particular data type is ```int```.\n\nIf you write code like ```type(5)```, you'd get ```'int'``` as the output.\n\nIn Python, there are no primitive types. What does that mean? Every value that you see in a Python program, is an object, an instance of some ```class```.\n\nIn later sections, We'll understand what is a ```class```, and what is an object or an instance. For now, the most important thing for you to remember, is that behind every value, there is a ```class```.\n\n#### Snippet-01:\n\nLet's look at ```2.5```, which is a floating point value.\n\nIf you go ahead and do ```type(2.5)```, what would you see? You would see it's of type ```float``.\n\n```py\n\t\u003e\u003e\u003e type(2.5)\n\t\u003cclass 'float'\u003e\n\t\u003e\u003e\u003e type(2.55)\n\t\u003cclass 'float'\u003e\n```\n\nWhen you perform a division operation between two integers, there is a chance that the result of the operation is a ```float```. If you do ```5/2```, the result is ```2.5```.  If we were to do ```4/2```, even then it's of type ```float```.\n\n```py\n\t\u003e\u003e\u003e type(5/2)\n\t\u003cclass 'float'\u003e\n\t\u003e\u003e\u003e type(4/2)\n\t\u003cclass 'float'\u003e\n\t\u003e\u003e\u003e 4/2\n\t2.0\n\t\u003e\u003e\u003e 1 + 2\n\t3\n\n```\n\n\n\nAll the operations we looked at until now, can also be performed on floating point values.\n\n```py\n\t\u003e\u003e\u003e value1 = 4.5\n\t\u003e\u003e\u003e value2 = 3.2\n\t\u003e\u003e\u003e value1 + value2\n\t7.7\n\t\u003e\u003e\u003e value1 - value2\n\t1.2999999999999998\n\t\u003e\u003e\u003e value1 / value2\n\t1.40625\n\t\u003e\u003e\u003e value1 % value2\n\t1.2999999999999998\n\n```\n\n```value1 - value2``` returns ```1.299999999999998```. Why?\n\nFloating point numbers don't really represent accurate values. That's one of the things you need to always keep in mind.\n\nTypically, if you're doing any highly sensitive financial calculations, don't use ```float```s to represent your values. Instead, use ```Decimal```. More about it later.\n\nOperations can also be performed between ```int``` and ```float```.\n```py\n\t\u003e\u003e\u003e i + value1\n\t14.5\n\t\u003e\u003e\u003e i - value1\n\t5.5\n\t\u003e\u003e\u003e i / value1\n\t2.2222222222222223\n\t\u003e\u003e\u003e\n\n```\n\n Result of an operation between a ```int``` and a ```float```, is always a ```float```.\n\n#### Summary\n\nIn this step, we:\n\n* Looked at the two basic numeric types: ```int``` and ```float```.\n* Saw the basic operations you can do among ```int```s, among ```float```s, and also between ```int```s and ```float```s.\n\n### Step 02: Programming Exercise PE-DT-01\n\nIn this step, let's do a simple exercise with numeric values.\n\n#### Exercises\n\n1. You need to create a method called ```simple_interest```, and pass three parameters: ```principal```, ```interest``` and ```duration``` (in years). You also want to calculate the amount after the specific duration, and return it back. Call this method with a few example values.\n\nFor example, if you want to call ```simple_interest``` with ```10000```, with an interest of ```5``` percent, for a duration of ```5``` years, the correct answer would be as follows: ```10000``` is the principal. In addition to ```10000```, you get the interest. The interest for one year is ```10000 * 0.05```, as the interest figure is in percentage.So that's ```500``` a year, into ```5``` which is ```2500```. The result would be ```12500```, and this value should be printed.\n\n#### Solution 1\n\n```py\n\tdef calculate_simple_interest(principal, interest, duration) :\n\t\t    return principal * (1 + interest * 0.01 * duration)\n\n\tprint(calculate_simple_interest(10000,5,5))\n\n```\n\n#### Summary\n\nIn this step, we:\n\n* Wrote a very simple method to do a simple interest calculation\n\n### Step 03: Puzzles On Numeric Types\n\nIn this section, we are looking at numeric types. In this specific step, we would be looking at a few puzzles related to values of these types.\n\n#### Snippet-01:\n\nLet's create a simple variable ```i = 1```.  ```i = i + 1```. What would be the value of ```i``` after that?\n\n```py\n\t\u003e\u003e\u003e i = 1\n\t\u003e\u003e\u003e i = i + 1\n\t\u003e\u003e\u003e i\n\t2\n```\n\n It would be ```2```. There is a shortcut way of doing the same thing, by using the ```+=``` operator.\n\n```py\n\t\u003e\u003e\u003e i += 1\n\t\u003e\u003e\u003e i\n\t3\n\n```\n\nTypically in other programming languages, you can do something of this kind: ```i++```. There is no provision in Python to use increment operators like ```++```, in either prefix or suffix mode, like ```++i```, or ```i++```.\n```py\n\t\u003e\u003e\u003e i++\n\t  File \"\u003cstdin\u003e\", line 1\n\t    i++\n\t      ^\n\tSyntaxError: invalid syntax\n\t\u003e\u003e\u003e ++i\n\t3\n```\n\n\nLet's look at compound assignments.\n\n```py\n\t\u003e\u003e\u003e i += 1\n\t\u003e\u003e\u003e i\n\t4\n\t\u003e\u003e\u003e i -= 1\n\t\u003e\u003e\u003e i\n\t3\n\t\u003e\u003e\u003e i /= 1\n\t\u003e\u003e\u003e i *= 2\n\t\u003e\u003e\u003e i\n\t6.0\n\n```\n\nWhat you see here, is Dynamic Typing in Python. The type of a variable can change during the lifetime of the program.\n```py\n\u003e\u003e\u003e i = 2\n\u003e\u003e\u003e type(i)\n\u003ctype 'int'\u003e\n\u003e\u003e\u003e i = i/2.0\n\u003e\u003e\u003e type(i)\n\u003ctype 'float'\u003e\n```\n\nLet's create a couple more numbers. ```number1 = 5``` and ```number2 = 2```. What could be the result of ```number1 / number2```? You know it, it's ```2.5``` .\n\n```number1 // nummber2``` truncates the value of ```2.5```, to ```2```.\n\n```py\n\t\u003e\u003e\u003e number1//number2\n\t2\n```\n\nIf you can do ```number1 // number2```, can you also do this: ```number1 //= number2```?\n\n```py\n\t\u003e\u003e\u003e number1 //= 2\n\t\u003e\u003e\u003e number1\n\t2\n\n```\n\n```5 ** 3``` is ```5``` 'to the power of' ```3```, which is ```5 * 5 * 5```, or ```125```.\n\n```py\n\t\u003e\u003e\u003e 5 ** 3\n\t125\n\t\u003e\u003e\u003e pow(5,3)\n\t125\n\n```\n\nThis can also be achieved by invoking ```pow(5, 3)```. We have an operator, as well as a method at our disposal.\n\nThe last thing we will look at, are type conversion functions.\n\nIf you need to convert an ```int``` value to a ```float```, or a ```float``` to an ```int```.\n\n```py\n\t\u003e\u003e\u003e int(5.6)\n\t5\n```\n\nWhat if you want to round a value? ```5.6``` is nearer to ```6``` than ```5```. You can use a function called ```round()```, and here,```round(5.6)``` gives the correct result ```6```.\n\n```py\n\t\u003e\u003e\u003e round(5.6)\n\t6\n\t\u003e\u003e\u003e round(5.4)\n\t5\n\t\u003e\u003e\u003e round(5.5)\n\t6\n\n```\n\n```round()``` can also allows you to specify number of decimals in the result.\n\n```py\n\t\u003e\u003e\u003e round(5.67, 1)\n\t5.7\n\t\u003e\u003e\u003e round(5.678, 2)\n\t5.68\n```\n\nYou can also convert ```int``` to ```float```, by using the function ```float()```.\n```py\n\t\u003e\u003e\u003e float(5)\n\t5.0\n\n```\n\n#### Summary\n\nIn this step, we:\n\n* Looked at a few corner cases related to your numeric types.\n* Examined the different operators available for use with values of numeric types\n* Learned about the usage of type conversion functions\n\n### Step 04: Introducing Boolean Type\n\nWe will now shift our attention to the ```bool``` data type.\n\nA boolean value is something which can be either \"true\" or \"false\".\n\n\n#### Snippet-01:\n\nIn Python, \"true\" is represented by ```True```, and \"false\" by ```False```. It's important to remember that it's ```True``` with a capital ```'T'```, and ```False``` with a capital ```'F'```.\n\n```py\n\t\u003e\u003e\u003e True\n\tTrue\n\t\u003e\u003e\u003e False\n\tFalse\n\t\u003e\u003e\u003e true\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'true' is not defined\n\t\u003e\u003e\u003e false\n\tTraceback (most recent call last):\n\t  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n\tNameError: name 'false' is not defined\n```\n\nThe boolean variable ```is_even``` indicates whether a number is even or not.\n```py\n\t\u003e\u003e\u003e is_even = True\n\t\u003e\u003e\u003e is_odd = False\n\n```\nLet's create a variable ```i = 10```. We want to find out if ```i \u003e 15```. What do you think is the result? ```False```.\n```py\n\t\u003e\u003e\u003e i = 10\n\t\u003e\u003e\u003e i \u003e 15\n\tFalse\n\t\u003e\u003e\u003e i \u003c 15\n\tTrue\n\n```\n\n In general, boolean values can represent the result of logical conditions.\n\nLet's look at other operations that can result in ```bool``` values. We looked at ```\u003e``` and ```\u003c```. Another operation which you can perform, is ```\u003e=```.\n\n```py\n\t\u003e\u003e\u003e i \u003e= 15\n\tFalse\n\t\u003e\u003e\u003e i \u003e= 10\n\tTrue\n\t\u003e\u003e\u003e i \u003e 10\n\tFalse\n\t\u003e\u003e\u003e i \u003c= 10\n\tTrue\n\t\u003e\u003e\u003e i \u003c 10\n\tFalse\n\n```\n\n`==` is the comparison operator. We are only comparing the value of ```i``` against ```10```, not changing its value.\n\n```py\n\t\u003e\u003e\u003e i == 10\n\tTrue\n\t\u003e\u003e\u003e i == 11\n\tFalse\n\n```\n\n#### Summary\n\nIn this step, we:\n\n* Were introduced to the ```bool``` data type\n* Learned that ```bool``` variables are useful handy while testing logical conditions\n\n### Step 05: Introducing Conditionals\n\nIn this step, let's look at ```if``` statement.\n\nSometimes you need to execute code only when certain conditions are true. You can use a ```if``` condition, which is the simplest conditional in Python. Let's look at an example.\n\n#### Snippet-01:\n\nLet's say ```i``` has a value of ```5```. You want to print something, only if ```i``` has a value greater than ```3```. How do you do that?\n\n```py\n\t\u003e\u003e\u003e i = 5\n\t\u003e\u003e\u003e if i\u003e3:\n\t...     print(f\"{i} is greater than 3\")\n\t...\n\t5 is greater than 3\n\n```\n\nThe syntax of the ```if``` is very simple: ```if``` followed by a condition; with the condition you want to check. It looks like:  ```if i\u003e3: ...``` You need to indent the body of the ```if``` with ```\u003cSPACE\u003e```s as usual.\n\nLet's say ```i``` has a value of ```2```. What would happen if we execute the same code again?\n\n```py\n\t\u003e\u003e\u003e i = 2\n\t\u003e\u003e\u003e if i\u003e3:\n\t...     print(f\"{i} is greater than 3\")\n\t...\n```\n\nYou would see that nothing is printed to the console. Based on the value of ```i``` , either the statement is executed, or it's not. That's what an ```if``` helps us to do.\n\nThe way you can think about an ```if```, is the body of code under the ```if``` is executed only when this condition is ```True```. If this condition is not ```True```, that code is not executed at all.\n\n```py\n\t\u003e\u003e\u003e if(False):\n\t...   print(\"False\")\n\t...\n\t\u003e\u003e\u003e if(True):\n\t...   print(\"True\")\n\t...\n\tTrue\n\n```\n\nLet's take two different numbers, say ```a = 5```, and ```b = 7```. We want to compare them, and predict if ```a``` is greater that ```b``` .\n```py\n\t\u003e\u003e\u003e a = 5\n\t\u003e\u003e\u003e b = 7\n\t\u003e\u003e\u003e if(a\u003eb):\n\t...   print(\"a is greater than b\")\n\t...\n\n\t\u003e\u003e\u003e a = 9\n\t\u003e\u003e\u003e if(a\u003eb):\n\t...   print(\"a is greater than b\")\n\t...\n\ta is greater than b\n\n```\n\n#### Summary\n\nIn this step, we:\n\n* Were introduced to the ```if``` statement, the simplest Python conditional\n* Understood how an ```if``` helps in implementing conditional program logic\n\n### Step 06: Classroom Exercise CE-DT-01\n\nIn this step, let's look at a couple of exercises with the if statement.\n\n#### Snippet-01:\n\nLet's say we define four variables: ```a = 1```, ```b = 2``` , ```c = 3``` and ```d = 5```. we want to find out, if ```a + b``` is greater than ```c + d```.\n\n```py\n\t\u003e\u003e\u003e a = 1\n\t\u003e\u003e\u003e b = 2\n\t\u003e\u003e\u003e c = 3\n\t\u003e\u003e\u003e d = 5\n\t\u003e\u003e\u003e if a+b \u003e c+d :\n\t...    print(\"a+b \u003e c +d\")\n\t...\n\t\u003e\u003e\u003e a = 9\n\t\u003e\u003e\u003e if a+b \u003e c+d :\n\t...    print(\"a+b \u003e c +d\")\n\t...\n\ta+b \u003e c +d\n\n```\n\nLet's say we are given three values meant to be the angles of a triangle.  Their values are ```angle1 = 30```,  ```angle2 = 20``` and ```angle3 = 60```. You want to find out if these three angles actually form a  valid triangle. You know that the sum of the angles of a triangle is always ```180``` degrees.\n\n```py\n\t\u003e\u003e\u003e angle1 = 30\n\t\u003e\u003e\u003e angle2 = 20\n\t\u003e\u003e\u003e angle3 = 60\n\t\u003e\u003e\u003e if(angle1 + angle2 + angle3 == 180):\n\t...      print(\"Valid Triangle\")\n\t...\n\t\u003e\u003e\u003e angle2 = 90\n\t\u003e\u003e\u003e if(angle1 + angle2 + angle3 == 180):\n\t...      print(\"Valid Triangle\")\n\t...\n\tValid Triangle\n\n```\n\nThe last exercise is to check if a number is even or not.\n\nHint L you need to use one of the operators we talked about earlier. That's right, use the modulo operator ```%```.\n\n```py\n\t\u003e\u003e\u003e i = 2\n\t\u003e\u003e\u003e if(i%2==0):\n\t...   print(\"i is even\")\n\t...\n\ti is even\n\n\t\u003e\u003e\u003e i = 3\n\t\u003e\u003e\u003e if(i%2==0):\n\t...   print(\"i is even\")\n\t...\n\n```\n\n#### Summary\n\nIn this step, we:\n\n* Looked at a few exercises related to the if statement, for writing and testing conditions.\n\n### Step 07 - Logical Operators - and or not\n\nIn this step, let's look at the different operators that can be used on ```bool``` values. These operators are called logical operators -  ```and```, ```or``` , ```not``` and ```^``` (xor).\n\nLet's say we have a value ```True```, and the other ```False```, and we want to play around with them.\n\nLogical operator ```and``` re","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floveneeshdhir%2Fpython-for-beginners","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floveneeshdhir%2Fpython-for-beginners","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floveneeshdhir%2Fpython-for-beginners/lists"}