FLOWCHARTS
A flowchart is a diagrammatic representation of an algorithm. A flowchart can be helpful for both writing programs and explaining the program to others.
Symbols Used In Flowchart
Symbol |
Purpose |
Description |
|
Flow line |
Indicates the flow of logic by connecting symbols. |
|
Terminal(Stop/Start) |
Represents the start and the end of a flowchart. |
|
Input/Output |
Used for input and output operation. |
|
Processing |
Used for arithmetic operations and data-manipulations. |
|
Decision |
Used for decision making between two or more alternatives. |
|
On-page Connector |
Used to join different flowline |
|
Off-page Connector |
Used to connect the flowchart portion on a different page. |
|
Predefined Process/Function |
Represents a group of statements performing one processing task. |
Examples of flowcharts in programming
1. Add two numbers entered by the user.
Flowchart to add two numbers
2. Find the largest among three different numbers entered by the user.
Flowchart to find the largest among three numbers.
3. Find all the roots of a quadratic equation ax2+bx+c=0
Flowchart to find roots of a quadratic equation
4. Find the Fibonacci series till term≤1000.
Flowchart fo display the Fibonacci Series
Evaluation Order
The following table gives the precedence table for Python, from the lowest precedence (least binding) to the highest precedence (most binding).
lambda: Lambda Expression if – else: Conditional expression or: Boolean OR and: Boolean AND not x: Boolean NOT in, not in, is, is not, <, #, >, >=, !=, == Comparisons, including membership tests and identity tests | Bitwise OR ^ Bitwise XOR & Bitwise AND <<, >> Shifts +, – Addition and subtraction *, /, //, % Multiplication, Division, Floor Division and Remainder +x, -x, ~x Positive, Negative, bitwise NOT ** Exponentiation x[index], x[index:index], x(arguments…), x.attribute Subscription, slicing, call, attribute reference (expressions…), [expressions…], {key: value…}, {expressions…} Binding or tuple display, list display, dictionary display, set display |
Conditional Statements
The if Statement
The if statement is used to check a condition: if the condition is true, we run a block of statements (called the if-block), else we process another block of statements (called the else-block). The else clause is optional.
number = 23
guess = int(input("Enter an Integer: "))
if guess == number:
#new block starts from here - note the indentation
print("Congratulations! You win it!")
elif guess < number:
print("Wrong guess! The number is higher than you think")
else:
print("Wrong guess! The number is lower than you think")
Output:
Enter an Integer: 35
Wrong guess! The number is lower than you think
We supply a string to the built-in input() function which prints it to the screen and waits for input from the user. Once we enter something and press enter key, the input() function returns what we entered, as a string. We then convert this string to an integer using int and then store it in the variable guess . Actually, the int is a class but all you need to know right now is that you can use it to convert a string to an integer (assuming the string contains a valid integer in the text).
Next, we compare the guess of the user with the number we have chosen. If they are equal, we print a success message. Notice that we use indentation levels to tell Python which statements belong to which block. This is why indentation is so important in Python. Notice how the if statement contains a colon at the end – we are indicating to Python that a block of statements follows.
There is no switch statement in Python. You can use an if..elif..else statement to do the same thing.
Programs in the Class
Eng = 0 Total= Eng +Maths+ Hin+Tel+Sci+SST print("Thank you for using this program!") |
Eng = 80 |
#Once I had been to the post-office to buy stamps of five rupees, two rupees and one rupee. t=43 #total amount i have paid to clerk print(“The total amount that i paid to clerk is:RS.{}".format(t)) #money that i paid #diff costs of stamps v5=5 #rs.5 cmq=av5*v5+av2*v2+av1*v1 #cost of minimum qty #av5 = 2 av2+= bam//v2 #av5=av5 +2 av1+= bam//v1 #av5=av5 +2 |
# check if eligible to vote in India or not |
Assignments
1. #WAP enter 3 sides, check if triangle is possible or not
# and also to check if the triangle is Isoceles or Equilateral or Scalene or Right angled
2. #Modify this program to make it look like your school's rule
# A >=80 B>=70 C>=60, D >=40 <40: Failed
3. Write if statements to do the following:
– If character variable taxCode is ’T’, increase price by adding the taxRate percentage of price to it.
– If integer variable opCode has the value 1, read in double values for X and Y and calculate and print their sum.
– If integer variable currentNumber is odd, change its value so that it is now 3 times currentNumber plus 1, otherwise change its value so that it is now half of currentNumber (rounded down when currentNumber is odd).
– Assign true to the boolean variable leapYear if the integer variable year is a leap year. (A leap year is a multiple of 4, and if it is a multiple of 100, it must also be a multiple of 400.)