Skip to main content

Posts

Showing posts from March, 2022

- For loop in Python -

Loops: Loops are control structures used to repeat a given section of code  ● a certain number of times or  ● until a particular condition is met.  How do we keep ourselves fit nowadays? We must be doing some exercises ..right?   The steps followed in doing the exercise are repeated many times ..isn’t it? Depending on the fitness level of the person, he can choose to repeat a step 10,20, or even 100 times. Now suppose, you want to write a program to simulate exercise steps. Is it feasible to write the same steps again and again? Also, how many times does it has to be repeated changes from person to person. Looping structures come to our rescue in such scenarios. Duplicating lines can be eliminated by repeating them a required number of times. ‘ for’ loop ‘for loops’ are used when you have a block of code that you want to repeat a fixed number of times. A series of numbers within a given range.  Note :  ● A range has 3 parameters -start, end, step. Here start and step is optional.  ●

- If structure in Python -

Decision Control Structures: The control structures help in making decisions when a program is being executed.  if Statement  : Depending on certain conditions, few statements are executed.  if-else Statement : D epending on a condition;( if true or false), statements are executed.  Elif : It’s a combination of else followed by if.  We all have made many decisions in life. (Here, decisions do not mean a big decision.)Most of our decisions depend on different conditions..isn’t it? some situations in which you had to make a decision?  ● What to order in a restaurant?  ● What to do in my free time?  ● Which movie to watch?  ● Which subject to take an elective?  ● During exams, which question to attempt first? Depending on where you are going, the dress you select to wear will also change ..isn’t it? So let's try an activity. Select the dress, according to a given condition. 1. If going to a party  2. If going out for playing  3. If going swimming  4. If it's cold outside  5. If go

- Operators in python -

  Operators  : Operators are special symbols in Python that carry out some specific operations. Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc.performing Note:  ● + when used with a number, adds the values  ● + when used with strings, concatenates two strings      Eg: “hello” +” world”=” hello world”  ● String and number cannot be added, unless the number is converted to string using str().  Eg: ”Python”+str(3) =” Python3”  ● Number * character concatenates the character that many times. Eg: 3 * ‘a’ = ‘aaa’  Now that we know how arithmetic operators work, let us see how python handles other operations. You must have watched/followed the cricket world cup. In that, they keep a tally of the highest run-scorer, highest wicket-taker, etc. How do they do that? By comparing values(runs/wickets); right? And what are the operators used here; The operators are <, >, etc  There are a few operators in Python, which help us in

---Variables and data type in Python ---

 Variables:  Variables can be considered as the name of a container. In other words, a variable is a container whose value can change depending on certain conditions.  When we allocate a value to a variable, it is known as a variable assignment.  In python, the syntax for it is   variable_name = value  Let's understand Variables with the help of a birthday card. My birthday 1 st July 5:00 PM  12/2, Rajouri Gardens  9898463123 Now depending on whose birthday it is and who is being invited, the details being filled in the ‘_______’ (blank space) keep on changing…right?  Imagine this ‘________’ as a container and the details being filled are the values. This value can change depending on circumstances. Variables can be considered as the name of a container. So in the above example,  date=”1 st July”  address=”12/2, Rajouri Gardens”  If the card is filled by someone else it can be,  date=”21 st July”  address=”34, MG road”  Here, date, address, etc are containers (variables), and “1 st

– 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 t