title
How to Use If Else Statements in Python (Python Tutorial #2)

description
This entire series in a playlist: https://goo.gl/eVauVX Keep in touch on Facebook: https://www.facebook.com/entercsdojo Subscribe to my newsletter: https://www.csdojo.io/news Support me on Patreon: https://www.patreon.com/csdojo Tips: 1. Follow along as I explain to make sure you understand everything 2. Ideally, work with a friend so you can help each other when you’re stuck 3. If you want to learn faster than I talk, I’d recommend 1.25x or 1.5x speed :) 4. Check the outline in the comment section below if you want to skip around. 5. Download the sample files here to follow along (they are Jupyter Notebook files): https://www.csdojo.io/python2 6. To make sure you don’t miss my future tutorial videos, sign up to my newsletter: https://www.csdojo.io/news 7. Have fun! If anything is unclear, please let me know in a comment. Keep in touch on Facebook: https://www.facebook.com/entercsdojo Subscribe to my newsletter: https://www.csdojo.io/news Support me on Patreon: https://www.patreon.com/csdojo

detail
{'title': 'How to Use If Else Statements in Python (Python Tutorial #2)', 'heatmap': [{'end': 743.433, 'start': 714.537, 'weight': 0.734}, {'end': 1164.742, 'start': 1060.292, 'weight': 0.712}], 'summary': 'The python tutorial for absolute beginners covers if-else statements and creating a bmi calculator, enabling viewers to download sample files from csdojo.io/python2. it also emphasizes the importance of programming language choices and using jupyter notebook for running, deleting, and adding cells.', 'chapters': [{'end': 55.41, 'segs': [{'end': 34.903, 'src': 'embed', 'start': 0.229, 'weight': 0, 'content': [{'end': 1.97, 'text': "Hey CS Dojo, it's YK here.", 'start': 0.229, 'duration': 1.741}, {'end': 6.552, 'text': 'Welcome to video number two of my Python tutorial for absolute beginners.', 'start': 2.49, 'duration': 4.062}, {'end': 11.894, 'text': "In this video, first of all, I'm going to answer a question I received on my last video,", 'start': 7.092, 'duration': 4.802}, {'end': 18.457, 'text': "and then I'm going to give you some additional commands you can use in Jupyter Notebook, for example, for adding and deleting cells.", 'start': 11.894, 'duration': 6.563}, {'end': 23.039, 'text': "And remember that you don't necessarily have to use Jupyter Notebook to follow this course.", 'start': 19.057, 'duration': 3.982}, {'end': 27.801, 'text': 'You can use, for example, PyCharm, which is a popular IDE for Python.', 'start': 23.579, 'duration': 4.222}, {'end': 34.903, 'text': "after that, I'm gonna cover if-else statements, how to use them and what they are, and By the end of this video,", 'start': 28.261, 'duration': 6.642}], 'summary': 'Python tutorial covering additional jupyter notebook commands and if-else statements for beginners.', 'duration': 34.674, 'max_score': 0.229, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI229.jpg'}, {'end': 59.692, 'src': 'embed', 'start': 34.903, 'weight': 1, 'content': [{'end': 43.726, 'text': "you'll be able to create a simple BMI calculator Which can tell if a person is overweight or not, given the person's height and weight.", 'start': 34.903, 'duration': 8.823}, {'end': 51.128, 'text': "I'm gonna put an outline of this video below so you don't have to watch the whole thing if you don't want to, and you can go to csdojo.io,", 'start': 43.726, 'duration': 7.402}, {'end': 55.41, 'text': 'slash python2 to download the sample files I create in this video.', 'start': 51.128, 'duration': 4.282}, {'end': 59.692, 'text': 'All right, first of all, let me answer a question I received on my last video.', 'start': 56.09, 'duration': 3.602}], 'summary': 'Create a bmi calculator to determine overweight status using provided height and weight data.', 'duration': 24.789, 'max_score': 34.903, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI34903.jpg'}], 'start': 0.229, 'title': 'Python tutorial for absolute beginners', 'summary': 'Covers answering questions, providing additional commands for jupyter notebook, discussing the use of if-else statements, and creating a bmi calculator, enabling viewers to download sample files from csdojo.io/python2.', 'chapters': [{'end': 55.41, 'start': 0.229, 'title': 'Python tutorial for absolute beginners', 'summary': 'Covers answering questions, providing additional commands for jupyter notebook, discussing the use of if-else statements, and creating a bmi calculator, enabling viewers to download sample files from csdojo.io/python2.', 'duration': 55.181, 'highlights': ['The tutorial covers answering a question from the last video and providing additional commands for Jupyter Notebook, as well as discussing the use of if-else statements and creating a BMI calculator.', 'Viewers can download the sample files from csdojo.io/python2 provided in the video for reference.', 'The video enables viewers to create a simple BMI calculator to determine if a person is overweight based on their height and weight.']}], 'duration': 55.181, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI229.jpg', 'highlights': ['Viewers can download the sample files from csdojo.io/python2 provided in the video for reference.', 'The tutorial covers answering a question from the last video and providing additional commands for Jupyter Notebook, as well as discussing the use of if-else statements and creating a BMI calculator.', 'The video enables viewers to create a simple BMI calculator to determine if a person is overweight based on their height and weight.']}, {'end': 382.287, 'segs': [{'end': 102.982, 'src': 'embed', 'start': 76.443, 'weight': 0, 'content': [{'end': 84.309, 'text': "Maybe you started learning C++ or Java already and you're wondering should I keep going with it or should I take this course for Python instead?", 'start': 76.443, 'duration': 7.866}, {'end': 88.412, 'text': "I would say keep going with whatever you're doing, as long as you enjoy it.", 'start': 85.009, 'duration': 3.403}, {'end': 95.377, 'text': "And then, if you want, you can take this course at the same time, because some of the concepts I'll teach are going to be the same,", 'start': 88.752, 'duration': 6.625}, {'end': 97.078, 'text': "regardless of which language you're using.", 'start': 95.377, 'duration': 1.701}, {'end': 102.982, 'text': 'So, for example, the method for swapping two variables I talked about in the last video.', 'start': 97.739, 'duration': 5.243}], 'summary': 'Continue learning c++ or java, consider python course for common concepts.', 'duration': 26.539, 'max_score': 76.443, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI76443.jpg'}, {'end': 312.981, 'src': 'embed', 'start': 288.075, 'weight': 3, 'content': [{'end': 293.736, 'text': 'The state of this Jupyter Notebook is stored in something called the kernel of this Jupyter Notebook.', 'start': 288.075, 'duration': 5.661}, {'end': 297.297, 'text': "That's basically represented by this command line interface.", 'start': 294.237, 'duration': 3.06}, {'end': 299.838, 'text': "This might look slightly different if you're using Windows.", 'start': 297.637, 'duration': 2.201}, {'end': 306.78, 'text': "And the kernel is what executes your code once you click the Run button, and it also stores all the variables that you've defined.", 'start': 300.218, 'duration': 6.562}, {'end': 312.981, 'text': 'So, to clear out the state of this Jupyter Notebook or to clear out all the variables you have defined,', 'start': 307.26, 'duration': 5.721}], 'summary': 'The jupyter notebook kernel stores and executes code, and stores defined variables.', 'duration': 24.906, 'max_score': 288.075, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI288075.jpg'}, {'end': 382.287, 'src': 'embed', 'start': 327.825, 'weight': 2, 'content': [{'end': 337.207, 'text': "So this kernel has been restarted now, and if we try to print b now, it'll give us an error because name a is not defined yet.", 'start': 327.825, 'duration': 9.382}, {'end': 341.802, 'text': "Also, remember that there's one kernel for each notebook file.", 'start': 338.16, 'duration': 3.642}, {'end': 351.127, 'text': "So if we had another notebook file and if we restart the kernel for this notebook file, that won't affect the other notebook at all,", 'start': 342.522, 'duration': 8.605}, {'end': 353.669, 'text': 'because that notebook will have a separate kernel.', 'start': 351.127, 'duration': 2.542}, {'end': 358.893, 'text': "Okay, so just to recap, we've learned how to use four commands in Jupyter Notebook.", 'start': 354.249, 'duration': 4.644}, {'end': 369.062, 'text': 'The first is running a cell and then deleting cells, adding cells, as well as restarting the kernel and clearing the output.', 'start': 359.393, 'duration': 9.669}, {'end': 377.249, 'text': "Okay, let's now delete all the cells we have here and restart the kernel and clear the output.", 'start': 370.143, 'duration': 7.106}, {'end': 382.287, 'text': "And let's dive into our main topic today, if-else statements.", 'start': 379.286, 'duration': 3.001}], 'summary': 'Jupyter notebook allows running, deleting, adding cells & restarting kernels. each notebook has a separate kernel.', 'duration': 54.462, 'max_score': 327.825, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI327825.jpg'}], 'start': 56.09, 'title': 'Making programming language choices and using jupyter notebook', 'summary': "Emphasizes the importance of pursuing one's interest in programming languages and considering learning another language simultaneously, while also covering the basics of using jupyter notebook, including running, deleting, and adding cells, as well as restarting the kernel and clearing the output.", 'chapters': [{'end': 97.078, 'start': 56.09, 'title': 'Choosing between web development and python', 'summary': "Emphasizes the importance of pursuing one's interest in programming languages, suggesting that individuals continue with their current choice while considering learning another language simultaneously, as the concepts taught may be applicable to different languages.", 'duration': 40.988, 'highlights': ["The importance of pursuing one's interest in programming languages is emphasized, with the suggestion to continue with the current choice while considering learning another language simultaneously.", 'The advice is to keep going with whatever language the individual is currently learning, as long as they enjoy it, and to consider taking a course for another language at the same time.', 'The concepts taught may be applicable to different languages, making it beneficial to continue with the current language while also learning another.']}, {'end': 382.287, 'start': 97.739, 'title': 'Jupyter notebook commands and kernels', 'summary': "Covers the basics of using jupyter notebook, including running, deleting, and adding cells, as well as restarting the kernel and clearing the output, with a demonstration of executing cells in any order and the functionality of the notebook's kernel.", 'duration': 284.548, 'highlights': ['The Jupyter Notebook commands include running a cell, deleting cells, adding cells, and restarting the kernel and clearing the output. The chapter discusses the four essential commands in Jupyter Notebook, comprising running a cell, deleting cells, adding cells, and restarting the kernel and clearing the output.', 'The state of the Jupyter Notebook, including variables, is stored in the kernel, which executes the code and preserves the variables defined. The state of the Jupyter Notebook, including variables, is stored in the kernel, which executes the code and preserves the variables defined, allowing for clearing the variables by restarting the kernel.', 'Demonstrates the functionality of executing cells in any order and the independence of kernels for different notebook files. The chapter demonstrates the functionality of executing cells in any order and clarifies that each notebook file has an independent kernel, ensuring no impact on other notebooks when restarting the kernel for a specific file.']}], 'duration': 326.197, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI56090.jpg', 'highlights': ['The advice is to keep going with whatever language the individual is currently learning, as long as they enjoy it, and to consider taking a course for another language at the same time.', 'The concepts taught may be applicable to different languages, making it beneficial to continue with the current language while also learning another.', 'The Jupyter Notebook commands include running a cell, deleting cells, adding cells, and restarting the kernel and clearing the output.', 'The state of the Jupyter Notebook, including variables, is stored in the kernel, which executes the code and preserves the variables defined, allowing for clearing the variables by restarting the kernel.', 'Demonstrates the functionality of executing cells in any order and clarifies that each notebook file has an independent kernel, ensuring no impact on other notebooks when restarting the kernel for a specific file.']}, {'end': 1183.605, 'segs': [{'end': 473.115, 'src': 'embed', 'start': 383.147, 'weight': 1, 'content': [{'end': 384.747, 'text': 'Let me give you a quick example here.', 'start': 383.147, 'duration': 1.6}, {'end': 389.888, 'text': 'a is equal to 1 and b is equal to 2.', 'start': 385.507, 'duration': 4.381}, {'end': 402.291, 'text': 'And what if we wanted to show a message that something like a is less than b by printing this string only if a is actually less than b.', 'start': 389.888, 'duration': 12.403}, {'end': 422.713, 'text': "We can do this with if a less than b colon, so that's if space a space less than space b colon, enter into a new line and print a is less than b.", 'start': 403.686, 'duration': 19.027}, {'end': 426.634, 'text': 'And you need to indent this new line by four spaces.', 'start': 422.713, 'duration': 3.921}, {'end': 427.995, 'text': "So that's one, two, three, four.", 'start': 426.914, 'duration': 1.081}, {'end': 438.439, 'text': 'You could actually use a different number of spaces, for example, three spaces or five spaces, but using four spaces is a convention in Python.', 'start': 428.695, 'duration': 9.744}, {'end': 440.72, 'text': "So let's stick with four spaces in this video.", 'start': 438.499, 'duration': 2.221}, {'end': 448.403, 'text': 'So these two lines, if a less than b, print a is less than b, this whole thing is called an if clause.', 'start': 441.5, 'duration': 6.903}, {'end': 452.124, 'text': 'And after this if clause, you could have more code.', 'start': 449.283, 'duration': 2.841}, {'end': 457.287, 'text': 'For example, print not sure if a is less than b.', 'start': 452.365, 'duration': 4.922}, {'end': 467.532, 'text': 'And so this if condition only applies to this line in this example and Python knows that because of the colon sign here,', 'start': 458.507, 'duration': 9.025}, {'end': 471.214, 'text': 'as well as the four spaces that we have before this print line.', 'start': 467.532, 'duration': 3.682}, {'end': 473.115, 'text': "So let's try running the cell.", 'start': 471.714, 'duration': 1.401}], 'summary': 'Using if statement in python to compare variables a and b for printing a message if a is less than b.', 'duration': 89.968, 'max_score': 383.147, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI383147.jpg'}, {'end': 567.782, 'src': 'embed', 'start': 542.713, 'weight': 5, 'content': [{'end': 547.814, 'text': 'You need to be really careful about the number of spaces in front of each line, because if we had, for example,', 'start': 542.713, 'duration': 5.101}, {'end': 555.057, 'text': "four spaces in front of the first line and five spaces in front of the second line, it'll give us an error.", 'start': 548.514, 'duration': 6.543}, {'end': 559.518, 'text': 'So the error says indentation error, unexpected indent.', 'start': 555.577, 'duration': 3.941}, {'end': 567.782, 'text': "Let's fix that by deleting one space here, and now we have four spaces in front of each line, so it's gonna work again.", 'start': 560.379, 'duration': 7.403}], 'summary': 'Indentation errors can occur due to incorrect number of spaces in front of each line, leading to unexpected indent errors.', 'duration': 25.069, 'max_score': 542.713, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI542713.jpg'}, {'end': 743.433, 'src': 'heatmap', 'start': 714.537, 'weight': 0.734, 'content': [{'end': 723.041, 'text': 'For example, what if we wanted to deal with the case where is less than f and is equal to f and is greater than f separately?', 'start': 714.537, 'duration': 8.504}, {'end': 724.141, 'text': 'So those three cases.', 'start': 723.141, 'duration': 1}, {'end': 729.104, 'text': 'We can do that with l if, which stands for else if.', 'start': 725.022, 'duration': 4.082}, {'end': 743.433, 'text': 'So write l if e Double equal sign, F, new line, print, parentheses, double quotes, E is equal to F.', 'start': 729.824, 'duration': 13.609}], 'summary': 'Using l if to handle three cases of comparison between variables e and f.', 'duration': 28.896, 'max_score': 714.537, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI714537.jpg'}, {'end': 1060.292, 'src': 'embed', 'start': 1032.493, 'weight': 0, 'content': [{'end': 1035.016, 'text': "Okay, let's now create a simple BMI calculator.", 'start': 1032.493, 'duration': 2.523}, {'end': 1042.54, 'text': 'BMI is basically a number that can tell if a person is overweight or not, depending on their height and weight.', 'start': 1035.777, 'duration': 6.763}, {'end': 1045.803, 'text': "So let's say, hypothetically speaking,", 'start': 1043.502, 'duration': 2.301}, {'end': 1060.292, 'text': 'we have a person named YK and his height in meters again hypothetically speaking is 2 meters and his weight in kilograms is 90..', 'start': 1045.803, 'duration': 14.489}], 'summary': "Creating a bmi calculator to determine yk's weight status.", 'duration': 27.799, 'max_score': 1032.493, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI1032492.jpg'}, {'end': 1164.742, 'src': 'heatmap', 'start': 1060.292, 'weight': 0.712, 'content': [{'end': 1067.458, 'text': "Now, if you only know someone's height in feet and inches and weight in pounds, just use an online calculator to convert it.", 'start': 1060.292, 'duration': 7.166}, {'end': 1076.625, 'text': 'So you can just search for feet and inches to meters, and you should be able to find a good online calculator for that.', 'start': 1068.098, 'duration': 8.527}, {'end': 1089.29, 'text': "Okay, now the formula for finding the BMI is the person's weight in kilograms divided by this person's height in meters squared.", 'start': 1077.605, 'duration': 11.685}, {'end': 1102.075, 'text': 'And to express height in meters squared, you could either write height M times height M, or you can write height M double star two.', 'start': 1089.97, 'duration': 12.105}, {'end': 1104.857, 'text': 'And this double star just means to the power of.', 'start': 1102.696, 'duration': 2.161}, {'end': 1113.222, 'text': "And let's print this person's BMI here with print double quotes BMI and then BMI.", 'start': 1105.817, 'duration': 7.405}, {'end': 1120.466, 'text': "So this person would be not overweight if this person's BMI is less than 25.", 'start': 1113.742, 'duration': 6.724}, {'end': 1129.672, 'text': "So in that case, if BMI less than 25, let's print this person's name is not overweight.", 'start': 1120.466, 'duration': 9.206}, {'end': 1138.775, 'text': "And else, if BMI is greater than or equal to 25, we're going to print this person is overweight.", 'start': 1131.232, 'duration': 7.543}, {'end': 1142.157, 'text': "Let's see if YK is overweight here.", 'start': 1139.996, 'duration': 2.161}, {'end': 1144.618, 'text': "Okay, he's not.", 'start': 1143.978, 'duration': 0.64}, {'end': 1155.195, 'text': 'But what if he had 110 kilograms of weight? then his BMI would be 27.5 and YK would be overweight.', 'start': 1145.898, 'duration': 9.297}, {'end': 1164.742, 'text': "Okay, if you'd like to support me so I can keep making videos like this full time, just go to csdojo.io.php to find my Patreon page.", 'start': 1156.036, 'duration': 8.706}], 'summary': "Convert height and weight to bmi using online calculator and formula for bmi calculation. yk's bmi is 27.5, making him overweight.", 'duration': 104.45, 'max_score': 1060.292, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI1060292.jpg'}], 'start': 383.147, 'title': 'Python if-else statements', 'summary': 'Explains the python if-else statements, including examples with conditional statements and multiple conditions, and also demonstrates a bmi calculation with a hypothetical person named yk, showing how bmi can determine if a person is overweight.', 'chapters': [{'end': 567.782, 'start': 383.147, 'title': 'Python if clause example', 'summary': "Explains the python if clause using an example where 'a' is less than 'b', and demonstrates the use of four spaces and the colon sign to create the if clause, with successful outcomes and potential errors due to incorrect indentation.", 'duration': 184.635, 'highlights': ["The if clause in Python uses the 'if' keyword followed by the condition, a colon, and indentation by four spaces, and it allows for the execution of code based on the given condition.", "The example demonstrates the successful execution of the if clause when 'a' is less than 'b' by displaying the message 'a is less than b' and 'a is definitely less than b' using print statements.", 'Incorrect indentation, such as having different numbers of spaces before the code lines, can lead to errors, as seen in the example where an unexpected indent error occurred due to inconsistent indentation.', 'Python uses a colon and indentation by four spaces to define the scope of the if clause, distinguishing it from languages that use parentheses and curly brackets for the same purpose.']}, {'end': 1183.605, 'start': 568.342, 'title': 'Python if-else statements and bmi calculation', 'summary': 'Explains python if-else statements, including examples with conditional statements and multiple conditions, and also demonstrates a bmi calculation with a hypothetical person named yk, showing how bmi can determine if a person is overweight.', 'duration': 615.263, 'highlights': ['The chapter explains Python if-else statements, including examples with conditional statements and multiple conditions. The transcript provides detailed examples of using if-else statements in Python, including handling multiple conditions using if, else, and elif clauses.', 'The chapter demonstrates a BMI calculation with a hypothetical person named YK. The transcript showcases a BMI calculation formula and uses it to determine if the hypothetical person named YK is overweight based on his height and weight, with specific examples and conditions.']}], 'duration': 800.458, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/AWek49wXGzI/pics/AWek49wXGzI383147.jpg', 'highlights': ['The chapter demonstrates a BMI calculation with a hypothetical person named YK. The transcript showcases a BMI calculation formula and uses it to determine if the hypothetical person named YK is overweight based on his height and weight, with specific examples and conditions.', 'The chapter explains Python if-else statements, including examples with conditional statements and multiple conditions. The transcript provides detailed examples of using if-else statements in Python, including handling multiple conditions using if, else, and elif clauses.', "The if clause in Python uses the 'if' keyword followed by the condition, a colon, and indentation by four spaces, and it allows for the execution of code based on the given condition.", 'Python uses a colon and indentation by four spaces to define the scope of the if clause, distinguishing it from languages that use parentheses and curly brackets for the same purpose.', "The example demonstrates the successful execution of the if clause when 'a' is less than 'b' by displaying the message 'a is less than b' and 'a is definitely less than b' using print statements.", 'Incorrect indentation, such as having different numbers of spaces before the code lines, can lead to errors, as seen in the example where an unexpected indent error occurred due to inconsistent indentation.']}], 'highlights': ['The tutorial covers answering a question from the last video and providing additional commands for Jupyter Notebook, as well as discussing the use of if-else statements and creating a BMI calculator.', 'The video enables viewers to create a simple BMI calculator to determine if a person is overweight based on their height and weight.', 'The concepts taught may be applicable to different languages, making it beneficial to continue with the current language while also learning another.', 'The Jupyter Notebook commands include running a cell, deleting cells, adding cells, and restarting the kernel and clearing the output.', 'The state of the Jupyter Notebook, including variables, is stored in the kernel, which executes the code and preserves the variables defined, allowing for clearing the variables by restarting the kernel.', 'The chapter demonstrates a BMI calculation with a hypothetical person named YK. The transcript showcases a BMI calculation formula and uses it to determine if the hypothetical person named YK is overweight based on his height and weight, with specific examples and conditions.', 'The chapter explains Python if-else statements, including examples with conditional statements and multiple conditions. The transcript provides detailed examples of using if-else statements in Python, including handling multiple conditions using if, else, and elif clauses.', "The if clause in Python uses the 'if' keyword followed by the condition, a colon, and indentation by four spaces, and it allows for the execution of code based on the given condition.", 'Python uses a colon and indentation by four spaces to define the scope of the if clause, distinguishing it from languages that use parentheses and curly brackets for the same purpose.']}