From JOYCE, 2 Months ago, written in Python.
Embed
Hits: 164
1. '''Q.3) Create a module length conversions.py that stores functions for various length conversions
2.    1.mile to km()
3.    2.km to mile()
4.    3.feet to inches()
5.    4.inches to feet()
6.    Create a new program and invoke these functions '''
7.
8. # length conversions.py
9.
10. def miles_to_km(miles):
11.     km=miles*1.6
12.     print("Miles to km:",km)
13.
14. def km_to_miles(km):
15.     miles=km*0.6
16.     print("Km to Miles:",miles)
17.
18. def feet_to_inches(feet):
19.     inches=feet*12
20.     print("Feet to inches",inches)
21.
22. def inches_to_feet(inches):
23.     feet=inches/12
24.     print("Inches to feet",feet)
25.
26. #--main--#
27. ch=1
28. while ch!=5:
29.     print('-'*20)
30.     print("1. To convert miles to km")
31.     print("2. To convert km to miles")
32.     print("3. To convert feet to inches")
33.     print("4. To convert inches too feet")
34.     print("5. To Exit")
35.     ch=int(input("Enter choice"))
36.     if ch==1:
37.         miles=float(input("Enter miles to convert"))
38.         miles_to_km(miles)
39.     elif ch==2:
40.         km=float(input("Enter km to convert"))
41.         km_to_miles(km)
42.     elif ch==3:
43.         feet=int(input("Enter feet to convert"))
44.         feet_to_inches(feet)
45.     elif ch==4:
46.         inches=int(input("Enter inches to convert"))
47.         inches_to_feet(inches)
48.     elif ch!=5:
49.         print("Invalid choice")
50.
51.
52. ''' OUTPUT '''
53. 1. To convert miles to km
54. 2. To convert km to miles
55. 3. To convert feet to inches
56. 4. To convert inches too feet
57. 5. To Exit
58. Enter choice 1
59. Enter miles to convert 20
60. Miles to km: 32.0
61. --------------------
62. 1. To convert miles to km
63. 2. To convert km to miles
64. 3. To convert feet to inches
65. 4. To convert inches too feet
66. 5. To Exit
67. Enter choice 2
68. Enter km to convert 4
69. Km to Miles: 2.4
70. --------------------
71. 1. To convert miles to km
72. 2. To convert km to miles
73. 3. To convert feet to inches
74. 4. To convert inches too feet
75. 5. To Exit
76. Enter choice 3
77. Enter feet to convert 5
78. Feet to inches 60
79. --------------------
80. 1. To convert miles to km
81. 2. To convert km to miles
82. 3. To convert feet to inches
83. 4. To convert inches too feet
84. 5. To Exit
85. Enter choice 4
86. Enter inches to convert 70
87. Inches to feet 5.833333333333333
88. --------------------
89. 1. To convert miles to km
90. 2. To convert km to miles
91. 3. To convert feet to inches
92. 4. To convert inches too feet
93. 5. To Exit
94. Enter choice 5
95. --------------------