Page 62 - PYTHON-12
P. 62

Practical File






                               Class XII - Computer Science with Python(083)


               Program 1:  Program to enter two numbers and print the arithmetic operations like +,-,*,
               /, // and %.

               Solution:

               #Program for Arithmetic Calculator


               result = 0

               val1 = float(input("Enter the first value :"))

               val2 = float(input("Enter the second value :"))


               op = input("Enter any one of the operator (+,-,*,/,//,%)")

               if op == "+":

                   result = val1 + val2


               elif op == "-":

                   result = val1 - val2

               elif op == "*":


                   result = val1 * val2

               elif op == "/":


                   if val2 == 0:

                       print("Please enter a value other than 0")

                   else:


                       result = val1 / val2

               elif op == "//":

                   result = val1 // val2


               else:

                   result = val1 % val2
   57   58   59   60   61   62   63   64   65   66   67