Computer Science, asked by Ranikush54, 1 year ago

Write a bython program to
Tenter to numbers caculate
and print their sum,
multiplication, subtraction
and divison​

Answers

Answered by tripathyspandan23
2

Explanation:

  1. # Python Program - Addition Subtraction Multiplication Division
  2. print("Enter 'x' for exit.");
  3. print("Enter any two number: ");
  4. num1 = input();
  5. num2 = input();
  6. if num1 == 'x':
  7. exit();
  8. else:
  9. ch = input("Enter operator (+,-,*,/): ");
  10. if ch == '+':
  11. res = int(num1) + int(num2);
  12. print(num1, "+", num2, "=", res);
  13. elif ch == '-':
  14. res = int(num1) - int(num2);
  15. print(num1, "-", num2, "=", res);
  16. elif ch == '*':
  17. res = int(num1) * int(num2);
  18. print(num1, "*", num2, "=", res);
  19. elif ch == '/':
  20. res = int(num1) / int(num2);
  21. print(num1, "/", num2, "=", res);
  22. else:
  23. print("Strange input..exiting..");
Answered by AbhijithPrakash
3

#  First we'll need to make the user input the numbers simultaneously.

# So, I'll be using two variables; 'a' and 'b'.

a=int(input("Enter the first number : "))

b=int(input("Enter the second number : "))

# As we have both the values we can calculate the required values.

# I gotta be be making it more interesting. For that I will be using a new variable 'o'.

o=str(input("Enter the symbol for the operation (+, -, *, /) : "))

if o=='+':

   print("The sum is : ", a+b)

elif o=='-':

   print("The difference is : ", a-b)

elif o=='-':

   print("The product is : ", a*b)

elif o=='-':

   print("The quotient is : ", a/b)

else:

   print("Invalid Character.")

Attachments:
Similar questions