Page 356 - Artificial Intellegence_v2.0_Class_9
P. 356

S. No.                                          Program
              19    Input a number and check if the number is positive, negative or zero and display an appropriate
                    message
                    N=int(input("Enter a number:"))
                    if N<0:
                      print(N," is a -ve number")
                    elif N==0:
                                                                                 Output:
                      print(N," is entered")
                                                                                 Enter a number: 5
                    else:
                                                                                 5  is a +ve number
                      print(N," is a +ve number")
              20    To print first 10 natural numbers

                    for i in range(1,11):
                       print(i,end="!")
                                                                                 Output:
                    Output:
                                                                                 1!2!3!4!5!6!7!8!9!10!
                    1!2!3!4!5!6!7!8!9!10!
              21    To print first 10 even numbers                               Output:
                                                                                 2
                    for i in range(1,11):
                                                                                 4
                       print(2*i)
                                                                                 6
                                                                                 8
                                                                                 10
                                                                                 12
                                                                                 14
                                                                                 16
                                                                                 18
                                                                                 20
              22    To print odd numbers from 1 to n

                    N=int(input("Enter the term :"))
                                                                                 Output:
                    for i in range(1,N+1):                                       Enter the term : 7

                        print(2*i-1,end=",")                                     1,3,5,7,9,11,13,
              23    To print sum of first 10 natural numbers

                    S=0

                    for i in range(1,11):
                                                                                 Output:
                       S+=i
                                                                                 The sum is  55
                    print("The sum is ",S)
              24    Program to find the sum of all numbers stored in a list

                    S=0

                    for i in [1,2,3,4,5]:
                                                                                 Output:
                        S+=i
                                                                                 The sum is  15
                    print("The sum is ",S)



              354     Touchpad Artificial Intelligence (Ver. 2.0)-IX
   351   352   353   354   355   356   357   358   359   360   361