-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.py
More file actions
85 lines (85 loc) · 2.04 KB
/
Copy pathtask2.py
File metadata and controls
85 lines (85 loc) · 2.04 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def add(a,b):
sum=(a+b)
return sum
def sub(a,b):
diff=(a-b)
return diff
def mul(a,b):
prod=a*b
return prod
def div(a,b):
quo=a/b
return quo
def exp(b,p):
res=pow(b,p)
return res
def sq(a):
res=pow(a,2)
return res
option= input('''Enter your choice:
1.Sum
2.Difference
3.Product
4.Quotient
5.Square
6.Exponent
''')
if(option=='1'):
try:
a= float(input("Enter first number "))
b= float(input("Enter second number "))
except ValueError:
print("Enter integer values only!!")
else:
print("Result:")
print(add(a,b))
elif(option=='2'):
try:
a= float(input("Enter first number "))
b= float(input("Enter second number "))
except ValueError:
print("Enter integer values only!!")
else:
print("Result:")
print(sub(a,b))
elif(option=='3'):
try:
a= float(input("Enter first number "))
b= float(input("Enter second number "))
except ValueError:
print("Enter integer values only!!")
else:
print("Result:")
print(mul(a,b))
elif(option=='4'):
try:
a= float(input("Enter first number "))
b= float(input("Enter second number "))
except ValueError:
print("Enter integer values only!!")
except ZeroDivisionError:
print("You cant divide by 0.Try to run again!")
else:
print("Result:")
print(div(a,b))
elif(option=='5'):
try:
a=int(input("enter a number: "))
except ValueError:
print("Enter integer values only!!")
else:
print("Result:")
print(sq(a))
elif(option=='6'):
try:
b=int(input("Enter base "))
p=int(input("Enter exponent "))
if(p < 0):
print("You cant enter negative integers as Power.Try to run again!")
else:
print("Result:")
print(exp(b,p))
except ValueError:
print("Enter integer values only!!")
else:
print(0)