Repository navigation
Expand file tree
/
Copy pathProject1.py
More file actions
61 lines (49 loc) · 1.53 KB
/
Copy pathProject1.py
File metadata and controls
61 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Making user friendly calculator
# 3 steps to follow for calculator
# 1. define function
# 2. user input
# 3. print result
# 1. define function operations
#1. function to add two numbers
def addition(num1, num2):
return num1 + num2
#2. function to sub two number
def subtraction(num1,num2):
return num1-num2
#3. function to multiplication two numbers
def multiplication (num1,num2):
return num1*num2
#4. function to division two numbers
def division(num1,num2):
return(num1/num2)
# 5. function to average two numbers
def average (num1,num2):
return (num1+num2)/2
# step 2 user input
print ("please select the operations: \n"\
"1.addition \n"\
"2.subtraction \n"\
"3.multiplication\n"\
"4.division \n"\
"5.average \n" )
select = int(input("please select the operation from 1 to 5: "))
number1 = int(input(" Enter a first number"))
number2 = int(input("Enter a second number"))
# step 3 print result
if select == 1:
print (number1, "+",number2,"=", \
addition(number1,number2))
elif select ==2:
print(number1,"-",number2,"= ", \
subtraction(number1,number2))
elif select ==3:
print(number1,"*",number2,"= ", \
multiplication(number1,number2))
elif select ==4:
print(number1,"/",number2,"= ", \
division(number1,number2))
elif select ==5:
print ("(",number1,"+",number2,")","/","2","= ", \
average(number1,number2))
else:
print("Invalid operation, Please select operations from 1 to 5!")