-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
76 lines (58 loc) · 1.66 KB
/
Copy pathfunction.py
File metadata and controls
76 lines (58 loc) · 1.66 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
# Task 1 : Create a function to calculate the operation
def calculate(a,b,operation):
if operation=="add":
return a+b
elif operation == "sub":
return a-b
elif operation =="Multi":
return a*b
elif operation == "div":
if b != 0:
return a/b
else:
return "cannot divide by zero"
else:
return "invalid operation"
print(calculate(10,15,"add"))
# Task 2: craete a function to check whether a number is even or odd
def check_even_odd(num):
if num % 2 == 0:
return "Even"
else:
return "Odd"
num = int(input("Enter the num"))
ans = check_even_odd(num)
print("The number is:", ans)
#Task 3: Create a function to find a factorial of the number
def fact(n):
if n < 0:
return "Factorial is not defined for negative numbers"
result = 1
for i in range(1, n + 1):
result *= i
return result
num = int(input("Enter a number:"))
print("Factorial of the given number is: ", fact(num))
#Task 4: Create a function to find the maximum of number
def find_max(a, b, c):
if a >= b and a >= c:
return a
elif b >= a and b >= c:
return b
else:
return c
print(find_max(10, 25, 15))
#Task 5: Create a function to check whether the string is plindrome or not
def palindrome(s):
if s == s[::-1]:
return "Palindrome"
else:
return "Not Palindrome"
# function call
print(palindrome("madam"))
print(palindrome("hello"))
#Task 6 : create a function to calculate the area of circle
def area_circle(r):
area = 3.14 * r * r
return area
print(area_circle(5))