1#Store number variables for the two numbers
2
3num1 = input('Enter first number: ')
4num2 = input('Enter second number: ')
5
6#the sum of the two numbers variable
7sum = float(num1) + float(num2)
8sum2 = float(num1) - float(num2)
9sum3 = float(num1) * float(num2)
10sum4 = float(num1) / float(num2)
11
12#what operator to use
13choice = input('Enter an operator, + = addition, - = subtraction, * = multiplication and / = division: ')
14#different sums based on the operators
15if choice == '+':
16 print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
17
18 if choice == '-':
19 print('The sum of {0} and {1} is {2}'.format(num1, num2, sum2))
20
21if choice == '*':
22 print('The sum of {0} and {1} is {2}'.format(num1, num2, sum3))
23
24if choice == '/':
25 print('The sum of {0} and {1} is {2}'.format(num1, num2, sum4))
26
1#My Personal Python calculator
2print("My Personal Python calculator")
3#inputs
4num1 = int(input('Enter the first number: '))
5num2 = int(input('Enter the second number: '))
6#opration req
7opr = input('Enter the type of operation you want to perform between your chosen two numbers: ')
8#calculation
9if opr=='+':
10 ans = num1 + num2
11 # displaying the answer
12 print(f'Your final answer is {ans}')
13elif opr == '- ':
14 ans = num1 - num2
15 # displaying the answer
16 print(f'Your final answer is {ans}')
17elif opr=='*':
18 ans = num1 * num2;
19 # displaying the answer
20 print(f'Your final answer is {ans}')
21elif opr=='/':
22 ans = num1 / num2
23 # displaying the answer
24 print(f'Your final answer is {ans}')
25else:
26 print('Invalid Entry!!!')
1#You can change Text at Inputs
2
3num1 = float(input("Enter Firt Number:"))
4num2 = float(input("Enter Second Number"))
5
6result= 0
7op = str(input("Enter an op(operator)"))
8#Gets Input Type--------
9try:
10 #U can make this in while loop ;-)
11 if op=="+":
12 result = num1 + num2
13 else if op=="-":
14 result = num1 - num2
15 else if op=="*":
16 result = num1 * num2
17 else if op=="/":
18 result = num1 / num2
19 else:
20 print("Invalid Input")
21 print("The result is " + result)
22except ZeroDivisionError:
23 print("U cant do that")
24
1num1 = input("Enter a Number : ")
2num2 = input("Enter a Number : ")
3result = (num1 * num2)
4print(result)
5# And then print out the result
1
2# Define variables for number inputs..
3num1 = int(input("Enter first number: "))
4num2 = int(input("Enter second number: "))
5
6# Input for operators
7op = input("Enter operator: ")
8
9# Functions for operations
10
11
12def add(num1, num2):
13 print('Result: ', num1 + num2)
14
15
16def subtract(num1, num2):
17 print('Result: ', num1 - num2)
18
19
20def multiply(num1, num2):
21 print('Result: ', num1 * num2)
22
23
24def division(num1, num2):
25 print('Result: ', num1 / num2)
26
27
28# Using the functions
29if op == '+':
30 add(num1=num1, num2=num2)
31elif op == '-':
32 subtract(num1=num1, num2=num2)
33elif op == '*':
34 multiply(num1=num1, num2=num2)
35elif op == '/':
36 division(num1=num1, num2=num2)
37else:
38 print('Invalid operator')
39
1#no gui
2
3def add(a,b):
4 result=a+b
5 print(result)
6
7def sub(a,b):
8 resulf=a-b
9 print(resulf)
10
11def mul(a,b):
12 resulf=a*b
13 print(resulf)
14
15def div(a,b):
16 resulf=a/b
17 print(resulf)
18
19a=int(input("enter th first number: "))
20b=int(input("enter th second number: "))
21op=input("enter the sign: ")
22
23if op=="+":
24 add(a,b)
25
26elif op=="-":
27 sub(a,b)
28
29elif op=="*":
30 mul(a,b)
31
32elif op=="/":
33 div(a,b)
34
35else:
36 print("invalid")