Question : Write a python program or script to take input for Two numbers and an operator (+ , – , * , / ) and Based on the operator calculate and print the result? This question can be asked in CBSE Class XII Computer science with Python Paper.
Code : Please follow the code given below
# Write a python program to take input for Two numbers and # an operator (+ , – , * , / ) and # Based on the operator calculate and print the result? x=int(input("Enter Number one : ")) y=int(input("Enter Number Two : ")) op=input("Enter Operator (+,-,*,/) : ") if(op=="+"): z=x+y print("Sum = ",z) elif(op=="*"): z=x*y print("Product = ",z) elif(op=="-"): if(x>y): z=x-y else: z=y-x print("Difference = ",z) elif(op=="/"): z=x/y print("Division = ",z) else: print("Invalid operator")
Output :