Page 271 - Ai_V1.0_Class9
P. 271

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:
                                                                                         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 N odd numbers
                            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)




                                                                                   Python Practical Questions   269
   266   267   268   269   270   271   272   273   274   275   276