Page 200 - Computer Science V2.0 Class 11
P. 200

z = int(input('Enter the number of days required by C alone: '))

                    #calculating the time if all three person work together
                    #formula used as per the question
                    days = (x * y * z)/(x*y + y*z + x*z)

                    #printing the total time taken by all three persons
                    print('Total time taken to complete work if A, B and C work together: ', days)
                13.  Write a program to enter two integers and perform all arithmetic operations on them.
               Ans.  def addition(a,b):
                        return a+b
                    def subtraction(a,b):
                        return a-b
                    def multiplication(a,b):
                        return a*b
                    def division(a,b):
                        return a/b

                    a = int(input("Enter First Number: "))
                    b = int(input("Enter Second Number: "))


                    print("Addition of {0} & {1} is : ".format(a,b), addition(a,b))
                    print("Subtraction of {0} & {1} is : ".format(a,b), subtraction(a,b))
                    print("Multiplication of {0} & {1} is : ".format(a,b), multiplication(a,b))
                    print("Division of {0} & {1} is : ".format(a,b),division(a,b))
                14.  Write a program to swap two numbers using a third variable.
               Ans.   def swap(num1,num2):
                        temp = num1
                        num1 = num2
                        num2 = temp
                        return num1,num2

                    num1 = int(input("Enter First Number: "))
                    num2 = int(input("Enter Second Number: "))

                    print('Numbers before swap',num1,num2)

                    num1, num2 = swap(num1,num2)

                    print('Numbers after swap',num1,num2)
                15.  Write a program to swap two numbers without using a third variable.
               Ans.  def swap(num1,num2):
                        num1, num2 = num2, num1
                        return num1,num2

                    num1 = int(input("Enter First Number: "))
                    num2 = int(input("Enter Second Number: "))

                    print('Numbers before swap',num1,num2)


               186   Touchpad Computer Science (Ver. 2.0)-XI
   195   196   197   198   199   200   201   202   203   204   205