-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPR_7_Moduler & Packager.py
More file actions
287 lines (243 loc) 路 9.32 KB
/
Copy pathPR_7_Moduler & Packager.py
File metadata and controls
287 lines (243 loc) 路 9.32 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import datetime
import time
import math
import random
import uuid
import string
def datetime_opt():
while True:
print()
print("Datetime & Time Operations:")
print("1. Display current date and time")
print("2. Calculate difference between two dates/times")
print("3. Format date into custom format")
print("4. Stopwatch")
print("5. Countdown Timer")
print("6. Back to Main Menu")
option = input("Enter your choice: ")
try:
if option == "1":
now = datetime.datetime.now()
print()
print("Current Date and Time:", now.strftime("%Y-%m-%d %H:%M:%S"))
print("================================")
continue
elif option == "2":
print()
d1 = input("Enter the first date (YYYY-MM-DD): ")
d2 = input("Enter the second date (YYYY-MM-DD): ")
date1 = datetime.datetime.strptime(d1, "%Y-%m-%d")
date2 = datetime.datetime.strptime(d2, "%Y-%m-%d")
diff = abs((date2 - date1).days)
print("Difference:", diff, "days")
print("================================")
continue
elif option == "3":
print()
fmt = input("Enter format (e.g. %d-%m-%Y): ")
print("Formatted Date:", datetime.datetime.now().strftime(fmt))
print("================================")
continue
elif option == "4":
print()
input("Press Enter to start stopwatch")
start = time.time()
input("Press Enter to stop")
end = time.time()
print("Elapsed time:", round(end - start, 2), "seconds")
print("================================")
continue
elif option == "5":
print()
sec = int(input("Enter seconds: "))
while sec > 0:
print(sec)
time.sleep(1)
sec -= 1
print("Time's up!")
print("================================")
continue
elif option == "6":
break
else:
print("Invalid Choice\n")
except Exception as e:
print("Error:", e)
def math_opt():
while True:
print()
print("Mathematical Operations:")
print("1. Calculate Factorial")
print("2. Solve Compound Interest")
print("3. Trigonometric Calculations")
print("4. Area of Geometric Shapes")
print("5. Back to Main Menu")
option = input("Enter your choice: ")
try:
if option == "1":
n = int(input("Enter a number: "))
print("Factorial:", math.factorial(n))
print("================================")
continue
elif option == "2":
p = float(input("Enter Principal amount: "))
r = float(input("Enter Rate of intrest (%): "))
t = float(input("Enter Time (in years): "))
ci = p * (1 + r / 100) ** t
print("Compound Interest:", round(ci, 2))
print("================================")
continue
elif option == "3":
angle = float(input("Enter angle in degrees: "))
rad = math.radians(angle)
print("sin:", math.sin(rad))
print("cos:", math.cos(rad))
print("tan:", math.tan(rad))
print("================================")
continue
elif option == "4":
r = float(input("Radius: "))
print("Area:", math.pi * r * r)
print("================================")
continue
elif option == "5":
break
else:
print("Invalid choice")
except Exception as e:
print("Error:", e)
def random_opt():
while True:
print()
print("Random Data Generation:")
print("1. Generate Random Number")
print("2. Generate Random List")
print("3. Create Random Password")
print("4. Generate Random OTP")
print("5. Back to Main Menu")
option = input("Enter your choice: ")
try:
if option == "1":
print("Random Number:", random.randint(1, 100))
print("================================")
continue
elif option == "2":
n = int(input("Enter List size: "))
print("Random List:", [random.randint(1, 50) for _ in range(n)])
print("================================")
continue
elif option == "3":
length = int(input("Enter Password length: "))
chars = string.ascii_letters + string.digits + "@#$!"
password = "".join(random.choice(chars) for _ in range(length))
print("Generated Password:", password)
print("================================")
continue
elif option == "4":
otp = random.randint(100000, 999999)
print("Generated OTP:", otp)
print("================================")
continue
elif option == "5":
break
else:
print("Invalid choice")
except Exception as e:
print("Error:", e)
def uuid_opt():
print()
print("Generated Unique Identifiers :")
print("Generated UUID :-",uuid.uuid4())
print("================================")
def file_opt():
while True:
print()
print("File Operations (Custom Module):")
print("1. Create a new file")
print("2. Write to a file")
print("3. Read from a file")
print("4. Append to a file")
print("5. Back to Main Menu")
option = input("Enter your choice: ")
try:
if option == "1":
name = input("Enter File name: ")
open(name, "w").close()
print("File created successfully!")
print("================================")
continue
elif option == "2":
name = input("Enter File name: ")
data = input("Enter data to write : ")
with open(name, "w") as f:
f.write(data)
print("Data Written successfully")
print("================================")
continue
elif option == "3":
name = input("Enter File name: ")
with open(name, "r") as f:
print("\nFile Content:\n", f.read())
print("================================")
continue
elif option == "4":
name = input("Enter File name: ")
data = input("Enter the data: ")
with open(name, "a") as f:
f.write("\n"+data)
print("Appended")
print("================================")
continue
elif option == "5":
break
else:
print("Invalid choice")
except Exception as e:
print("Error:", e)
def explore_opt():
print()
print("Explore Module Attributes (dir()):")
try:
mod = input("Enter module name to explore: ")
module = __import__(mod)
print("Available Attributes in math module :\n", dir(module))
print("================================")
except Exception as e:
print("Error:", e)
def main():
print()
print("==============================")
print("Welcome to Multi-Utility Toolkit")
print("==============================")
while True:
print("Choose an option:")
print("1. Datetime and Time Operations")
print("2. Mathematical Operations")
print("3. Random Data Generation")
print("4. Generate Unique Identifiers (UUID)")
print("5. File Operations (Custom Module)")
print("6. Explore Module Attributes (dir())")
print("7. Exit")
print("==============================")
option = input("Enter your choice: ")
if option == "1":
datetime_opt()
elif option == "2":
math_opt()
elif option == "3":
random_opt()
elif option == "4":
uuid_opt()
elif option == "5":
file_opt()
elif option == "6":
explore_opt()
elif option == "7":
print("==============================")
print("Thank you for using the Toolkit!")
print("==============================")
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()