forked from solygambas/python-openai-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25-debugging-code.py
42 lines (34 loc) · 1.27 KB
/
25-debugging-code.py
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
import random
from datetime import datetime, timedelta
def generate_dummy_data(n):
identifiers = ["ACAD", "LEARN", "DUMMY"]
start_date = datetime.now().date()
stock_data = []
for i in range(n):
current_date = start_date + timedelta(days=i)
for identifier in identifiers:
if i == 0:
price = round(random.uniform(50, 200), 2)
else:
prev_price = next(
(
data[1]
for data in stock_data
if data[0] == identifier
and data[2] == current_date - timedelta(days=1)
),
None,
)
if prev_price is None:
price = round(random.uniform(50, 200), 2)
else:
price = round(prev_price + random.uniform(-5, 5), 2)
stock_data.append((identifier, price, current_date))
return stock_data
if __name__ == "__main__":
n = input("Enter the number of dates for which data points should be generated: ")
dummy_data = generate_dummy_data(
int(n)
) # Convert the user input to an integer using int()
for data_point in dummy_data:
print(data_point)