Write a bython program to
Tenter to numbers caculate
and print their sum,
multiplication, subtraction
and divison
Answers
Answered by
2
Explanation:
- # Python Program - Addition Subtraction Multiplication Division
- print("Enter 'x' for exit.");
- print("Enter any two number: ");
- num1 = input();
- num2 = input();
- if num1 == 'x':
- exit();
- else:
- ch = input("Enter operator (+,-,*,/): ");
- if ch == '+':
- res = int(num1) + int(num2);
- print(num1, "+", num2, "=", res);
- elif ch == '-':
- res = int(num1) - int(num2);
- print(num1, "-", num2, "=", res);
- elif ch == '*':
- res = int(num1) * int(num2);
- print(num1, "*", num2, "=", res);
- elif ch == '/':
- res = int(num1) / int(num2);
- print(num1, "/", num2, "=", res);
- else:
- print("Strange input..exiting..");
Answered by
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
English,
6 months ago
Math,
6 months ago
Math,
1 year ago
Math,
1 year ago
Social Sciences,
1 year ago