-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay23.py
More file actions
80 lines (61 loc) · 2.31 KB
/
Day23.py
File metadata and controls
80 lines (61 loc) · 2.31 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
# Python Practice examples on functions
# Example 1 :defining a function to calculate LCM
def calculate_lcm(x, y):
# selecting the greater number
if x > y:
greater = x
else:
greater = y
while True:
if (greater % x == 0) and (greater % y == 0):
lcm = greater
break
greater += 1
return lcm
# taking input from users
print("Example 1: defining a function to calculate LCM")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# printing the result for the users
print("The L.C.M. of", num1, "and", num2, "is", calculate_lcm(num1, num2))
# Example 2: defining a function to calculate HCF
def calculate_hcf(x, y):
# selecting the smaller number
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller + 1):
if (x % i == 0) and (y % i == 0):
hcf = i
return hcf
# taking input from users
print("\nExample 2: defining a function to calculate HCF")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# printing the result for the users
print("The H.C.F. of", num1, "and", num2, "is", calculate_hcf(num1, num2))
# Example 3: defining a function to import and use the calendar module
import calendar
# ask of month and year
print("\nExample 3: Defining the function for a calender")
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
# display the calendar
print(calendar.month(yy, mm))
# Example 4: defining a function to calculate Volume of cuboid
def volume_of_cuboid(length, breadth, height):
return length * breadth * height
print("\nExample 4: Defining the function to calculate the Volume of cuboid: ")
nu1 = int(input("Enter Length: "))
nu2 = int(input("Enter Breadth: "))
nu3 = int(input("Enter Height: "))
print("\nThe Volume of cuboid of L, B, H :", nu1, ",", nu2, " and ", nu3, "is", volume_of_cuboid(nu1, nu2, nu3))
# Example 5: defining a function to calculate Volume and surface area of cube
def cube(side):
volume = side ** 3
surface_area = 6 * (side ** 2)
return volume, surface_area
print("\nExample 5: Defining the function to calculate the Volume and surface area of cube: ")
s1 = int(input("Enter side value: "))
print("\nThe volume and Surface area of the Cube of side ", s1, "are", cube(s1))