Skip to main content

– Sequences, Algorithms and Programs in Python ---

 Before moving forward, Let's learn how to install Python software in your System which is very important for the further understanding of these topics.

Imagine, you are a regular customer of Uncle Sam’s Pizza restaurant, can you help Uncle Sam prepare the menu and take a printout of it? Which application will you use for that? You will type the menu using MS word and then take a printout of it. right?

 So, you know that we can use MS Word to create documents.

Similarly, if you want to write a python program, you need an IDE (Integrated development environment). This IDE helps you to write a python program and then run it so that you can see the result/output of the program. 

Steps to install python/IDE in your local system. (Windows /MAC ) 

Note: Prerequisite for installing python in Windows- Windows 8 or above.

go to this website. 

1. Click on download python as per your OS. Mac users may download the Mac version. Windows users download depending on 32-bit or 64-bit.











2. Run the downloaded .exe file.











3. Select both checkboxes and then click on install now.

4. Allow the installer to make changes to a computer.

5. Wait till the installation completes.

 6. Once installation is complete, you will get a screen like this.










The name of the IDE we are using is IDLE (Integrated Development and Learning Environment.) 

Now let's understand how to write a program in python.

 1. Go to run-> type IDLE->click on it Or Goto the folder where Python is installed->open IDLE.

 2. To write a new code, Click on File->New File.










3. You can enter the code in the white area. To run code written, 

1. Click on Run->Run Module 











2. The python shell will open showing the output.

we have successfully installed python in your system.


Sequence:

The sequence is the correct order of doing a task.

 Let's understand the sequence with a basic example.

Do you know how to make a pizza? Have you ever tried making your own homemade pizza? Let's make one now.

1. Prepare the dough and roll it into a circle.

 2. Put on the pizza sauce, cheese, and toppings.

 3. Put the pizza in the oven.

 4. Bake until the pizza is crispy and golden brown. 

Now tell me, is it possible to skip steps 2 & 3 and arrive at step 4 from step 1 directly. Is it possible to do step 2 before step 1? No right?

When things are arranged in the correct sequence; it is not possible to skip a step or alter the sequence. It has to be followed as it is. Correct ordering is important because if we don't follow the correct order we will not get the correct result.

The same is the case when you are giving instructions to the computer. Each step of the sequence has to be followed as it is. 

Algorithm: 

 An algorithm is the set of instructions given in the correct order(sequence) to complete a task. It can be in English or any other language understandable by the user.

Do you know, just now you came up with the algorithm to make pizza. But do you think, the computer will understand if you give these instructions in English? Correct!! So if you want to give instructions to a computer, it has to be in some programming language understandable by the computer. 

Program:

A program is a set of instructions given to a computer, in some programming language. The algorithm serves as a blueprint to write a program. Alright, now let's watch something to understand this in a better way!

Play Video.

What happens in the video? The dad is not able to make the sandwich following the kid’s instructions, isn’t it? 

And why is that? 

● the sequence of the algorithm wasn't correct and that is the reason that the final result was not what the dad wanted. 

● the algorithm has to be very specific if you need the desired result. So did you enjoy it

Now let’s move on and help Uncle Sam in the restaurant.

Uncle Sam wants to help the customers in all possible ways. So, can you tell me the algorithm to place the order in the restaurant, so that Uncle Sam can display it as a tip?

 ● Go to the counter.

 ● Tell the choice of pizza and quantity required.

 ● The salesman places the order and generates the bill. 

● Make the payment.

● Get balance.

● Wait for your order to be ready Now suppose the restaurant wants the customer to enter their phone number, to maintain a record of the client. Develop an algorithm to validate if the phone number entered is correct or not. 

● Check the length of the phone number entered. It has to be 10. If not 10, the number is not valid 

● Check all the characters in the phone number. All of them should be numbers else it won’t be valid. Note: Looping through the number is not given since the student is not introduced to that concept.

Let’s try to write a program now for Uncle Sam who wants to display pizza-making steps in the kitchen. 




OUTPUT:

















program to print the menu of the restaurant. i.e.

(Welcome to Pizza Hub Today's Special

 ----------------------------------------

 1. Large Pizza Rs. 120

 2. Medium Pizza Rs. 80 

3. Small Pizza Rs. 60

 4. Toppings extra Rs. 10

 5. Extra cheese Rs. 15

 ---------------------------------------- 

Place the order on the counter and wait 10 mins for your order Thanks for giving us a chance to serve you.









Comments

Popular posts from this blog

- Animating characters using pygame -

If you see closely you can see that the mickey mouse animation is made out of a lot of shapes.  But to create something like this we need to make a very complex code. The other way around it is to use an image, other than the basic shapes, pygame also can show images.  Using images :  Steps to use images in my game: > find the image you want to use  > move it to the directory where you have created your code  > import/load image  To load the image we will first create an object and then use the image. load method to add the image to the object.  here, we have created an object called an image.  We then use the "pygame.image.load" to find the file in the directory ocean.png has to be replaced with the filename of your file.  To place the object on a particular point of the screen we use the blit function.  this function means that we are going to add the image onto the screen at position 0,0 mickey mouse is winking  Usi...

- Object Oriented Programming -

In OOP, we can represent an entity using a class.  A class bundles data (features/properties of entity - color, height, width) and functionality (movement, expression) together.  An instance of a class is known as an object.  Which is the only cartoon series that had predicted that Trump would be elected as the president of the USA and also predicted the coronavirus spread?   Answer: Simpsons.  Simpsons is a very popular animated show. You can build something similar with python.  But have you ever wondered, how Simpsons look the same in all the series? Only his movement looking and, expression change but his main features like color, height, and face look exactly the same all the time.  This is because we create a ‘blueprint’ of Simpsons and whenever we have to simulate him on screen we use this blueprint. This keeps a record of all the features of Simpsons and recreates it whenever we want.  This is where Object-Oriented Programming(OOP) h...