Page 329 - AI Ver 1.0 Class 9
P. 329

sum=sum + cube of last digit i.e. [(n%10)*(n%10)*(n%10)]
                               n=n/10
                  Step 6: IF sum==temp
                                 Print "Armstrong Number"
                              ELSE
                                 Print "Not Armstrong Number"
                  Step 7: Stop
               12.  Write a short note on indexing. Define the different types of indexing.

                                                               OR
                  Write a menu-driven program to find the volume of a sphere and a cylinder
              Ans.  Indexing refers to the way of addressing an element in a list. Python supports two types of indexing, forward indexing
                  and negative indexing. Forward indexing is when the index number begins with 0 till length-1 and we refer the elements
                  from left to right. Negative indexing is when the index number begins with -1 till -length and we refer the elements
                  from right to left.
                                                               OR
                  print("Select the vessel whose volume you want to find: \n1. Sphere\n2. Cylinder")
                  a = int(input())
                  pi = 3.14

                  if(a == 1):
                       print("Enter the radius of the sphere: ")
                       r = int(input())
                       volume = ((4/3)*pi*r*r*r)
                       print("Volume of the sphere is: ",volume)
                  elif(a= =2):
                      print("Enter the radius of the cylinder: ")
                      r = int(input())
                      print("Enter the height of the cylinder: ")
                      h = int(input())
                      volume = pi*r*r*h
                      print("Volume of the cylinder is: ",volume)
                  else:
                      print("Invalid choice")
            C.  Write a program for the given instructions.

               1.  Input three numbers and print the largest of three numbers using if statement.

              Ans.  a=int(input("enter a number "))
                  b=int(input("enter a number "))
                  c=int(input("enter a number "))
                  larg=a
                  if b>larg:
                      larg=b
                  if c>larg:
                       larg=c
                  print("largest of all is ",larg)


                                                                                Introduction to Python  327
   324   325   326   327   328   329   330   331   332   333   334