Page 399 - Ai_417_V3.0_C9_Flipbook
P. 399

Step 2   Input N1, N2, op
                 Step 3   if op is same as that of '+' then                               Flowchart

                              Display N1+N2                                                 START
                 Step 4   else, if op is same as that of '-' then
                              Display N1-N2                                              Input N1, N2
                 Step 5   else, if op is same as that of '*' then

                              Display N1*N2
                                                                                              Is     Yes    Display
                 Step 6   else                                                            op == "+"?       N1 + N2
                               Display "Sorry! Invalid Operator"
                 Step 7   Stop                                                                 No

                                                                                              Is     Yes    Display
                 Source Code:                                                             op == "–"?        N1 – N2

                 N1=int(input("Enter First Number:"))
                                                                                               No
                 N2=int(input("Enter Second Number:"))
                                                                                              Is
                 op=input("Enter an operator(+, –, * only):")                                        Yes    Display
                                                                                          op == "*"?        N1 * N2
                 if op=="+":
                                                                                               No
                     print("The addition is", N1+N2)
                                                                                           Display
                 elif op=="–":                                                     "Sorry! Invalid Operator"

                     print("The subtraction is", N1–N2)
                 elif op=="*":                                                              STOP

                     print("The multiplication is", N1*N2)
                 else:

                     print("Sorry! Invalid Operator")
                 Output:

                 Enter First Number: 5
                 Enter Second Number: 4

                 Enter an operator(+,–,* only): *
                 The multipication is 20
                  Program 8:  To input a number and check whether the number is positive of negative.

                 Algorithm
                 Step 1   Start

                 Step 2   Input Num
                 Step 3   if Num is same as 0:
                               Display "You entered zero"
                 Step 4   else, if Num is greater than 0:

                               Display "You entered +ve Number"




                                                                                        Introduction to Python  397
   394   395   396   397   398   399   400   401   402   403   404