#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
Comments
Post a Comment