Page 341 - Artificial Intellegence_v2.0_Class_9
P. 341

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)
               2.  Input a number and print the table of a number in a tabular form.

              Ans.  num=int(input("enter a number "))
                  for i in range(1,11):
                      print(num,"*",i,"=",num*i)
               3.  Input a character and check whether it is an uppercase, lowercase character or a digit or any other special character.

              Ans.  ch = input("enter a character :")
                  if ch>='A' and ch<='Z':
                      print("Uppercase")
                  elif ch>='a' and ch<='z':
                      print("Lowercase")
                  elif ch>='0' and ch<='9':
                      print("Number")
                  else:
                      print("Special Character")
               4.  Print the sum of even or odd numbers of first n natural numbers.

              Ans.  n=int(input("Enter range of natural numbers :"))
                  sumeven=sumodd=0
                  i=0
                  while i<=n:

                                                                                   Introduction to Python  339
   336   337   338   339   340   341   342   343   344   345   346