Posts

Showing posts from August, 2023

#22 Python Tutorial for Beginners | Break Continue Pass in Python

  #22 Python Tutorial for Beginners | Break Continue Pass in Python Introduction Welcome back! In the previous videos, we discussed loops in Python, specifically the for loop and the while loop. In this video, we'll talk about three important keywords: break, continue, and pass. These keywords are useful when it comes to controlling the flow of our code. To demonstrate their usage, let's design a simple vending machine simulation. Vending Machine Simulation First, we'll start by taking input from the user to determine the number of candies they want. Then, we'll use a while loop to print the word "candy" as many times as the user requested. Let's write the code: x = int(input("How many candies do you want? "))i = 1while i <= x: print("Candy") i += 1 When you run this code, it will ask you for the number of candies you want. For example, if you enter 4, it will print "Candy" four times. This is how the vending machine

#20 Python Tutorial for Beginners | While Loop in Python

  #20 Python Tutorial for Beginners | While Loop in Python Loops in Python In programming, loops are used to repeat a set of statements multiple times. Instead of manually copying and pasting the same code, we can use loops to automate the process. There are two types of loops in Python: while loop and for loop. In this blog, we will focus on the while loop. While Loop The while loop is used to repeat a set of statements as long as a specific condition is true. The basic structure of a while loop is as follows: while condition: # code to be repeated Here, the condition is checked before each iteration of the loop. If the condition is true, the code inside the loop is executed. This process continues until the condition becomes false. Let's understand this with an example. Suppose we want to print the statement "That is good" multiple times. We can use a while loop to do that. i = 1while i <= 5: print("That is good") i = i + 1 In this example, we init