Page 304 - AI Ver 1.0 Class 9
P. 304

print("The addition is", N1+N2)

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

        elif op=="*":
            print("The multiplication is", N1*N2)

        else:
            print("No Result! Wrong Operator Selected")

        Output:
        Enter first Number :5
        Enter second Number :4

        Enter an operator(+,–,* only) :*
        The multipication is 20

          Program 6:  To input a number and check whether the number is positive of negative.

        Algorithm                                                  Flowchart
        Start                                                                     START

        Input Num
        if Num is same as 0:                                                    Input Num

            Display "You entered zero"
        Otherwise, if Num is greater than 0:
                                                                                    Is      Yes    Display
            Display "You entered +ve Number"                                    Num = 0?            "Zero"
        Otherwise
                                                                                      No
            Display "You entered -ve Number"
        Stop                                                                        Is      Yes    Display
                                                                                Num > 0?          "+ve No"

        Source Code:                                                                  No

        Num=int(input("Enter a Number :"))                                        Display
                                                                                 "–ve No"
        if Num==0 :

            print("You entered zero")
                                                                                   STOP
        elif Num >0 :

            print("You entered a +ve number")
        else:

            print("You entered a –ve number")
        Output:

        Enter first Number :–4
        You entered a –ve number



                  302   Touchpad Artificial Intelligence-IX
   299   300   301   302   303   304   305   306   307   308   309