Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 12ec693

Browse files
committed
Fix code style issues with Black
1 parent 31a3a5f commit 12ec693

File tree

22 files changed

+503
-339
lines changed

22 files changed

+503
-339
lines changed

projects/Calculate Age/calculate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ def month_days(month, leap_year):
4646

4747
day = day + localtime.tm_mday
4848
print("%s's age is %d years or " % (name, year), end="")
49-
print("%d months or %d days" % (month, day))
49+
print("%d months or %d days" % (month, day))

projects/Calculate Age/src/calculate_age.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
def age_calculator(name, age):
66
"""
7-
Calculate user's age in years, month, and days
8-
based on current date and print.
7+
Calculate user's age in years, month, and days
8+
based on current date and print.
99
10-
Args:
11-
name (str): user's name.
12-
age (int): user's age in years.
10+
Args:
11+
name (str): user's name.
12+
age (int): user's age in years.
1313
14-
Returns:
15-
None.
16-
"""
14+
Returns:
15+
None.
16+
"""
1717
localtime = time.localtime(time.time())
1818

1919
year = int(age)
@@ -36,7 +36,3 @@ def age_calculator(name, age):
3636
day += localtime.tm_mday
3737

3838
return f"{name}'s age is {year} years or {month} months or {day} days"
39-
40-
41-
42-

projects/Calculate Age/src/main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
def main():
55
"""
6-
the user to input name and age, validate input,
7-
and calculates and displays the user age in years, months and days.
6+
the user to input name and age, validate input,
7+
and calculates and displays the user age in years, months and days.
88
9-
Args:
10-
None.
9+
Args:
10+
None.
1111
12-
Return:
13-
None.
14-
"""
12+
Return:
13+
None.
14+
"""
1515
input_name = input("input your name: ")
1616

1717
while True:
@@ -29,7 +29,6 @@ def main():
2929

3030
print(result)
3131

32+
3233
if __name__ == "__main__":
3334
main()
34-
35-

projects/Calculate Age/src/utilize_date.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
def judge_leap_year(year):
55
"""
6-
judge the leap year.
6+
judge the leap year.
77
8-
Args:
9-
year (int): To check the year.
10-
return:
11-
bool: Ture if the year is a leap year, False otherwise.
12-
"""
8+
Args:
9+
year (int): To check the year.
10+
return:
11+
bool: Ture if the year is a leap year, False otherwise.
12+
"""
1313
if isleap(year):
1414
return True
1515
else:
@@ -18,14 +18,14 @@ def judge_leap_year(year):
1818

1919
def month_days(month, leap_year):
2020
"""
21-
Returns the number of days in each month
21+
Returns the number of days in each month
2222
23-
Args:
24-
month (int): The month 1-12.
23+
Args:
24+
month (int): The month 1-12.
2525
26-
Returns:
27-
int: The number of days in the month.
28-
"""
26+
Returns:
27+
int: The number of days in the month.
28+
"""
2929
if month in [1, 3, 5, 7, 8, 10, 12]:
3030
return 31
3131
elif month in [4, 6, 9, 11]:

projects/Calculate Age/test_calculate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ def test_month_days():
1919
assert month_days(1, False) == 31
2020
assert month_days(11, True) == 30
2121

22+
2223
# "pytest -s test_calculate.py" to test this file

projects/Calculate Age/tests/test_calculate_age.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
from unittest.mock import patch
33
from calculate_age import age_calculator
44

5-
@patch('time.time', return_value=1621848668.0)
5+
6+
@patch("time.time", return_value=1621848668.0)
67
def test_age_calculator(mock_time):
78
"""
8-
Test the age_calculator function
9-
Mocks the current time and check if the age is calculated
10-
based on current time
9+
Test the age_calculator function
10+
Mocks the current time and check if the age is calculated
11+
based on current time
1112
"""
1213
name = "Chloe"
1314
age = 30
1415
expect_output = "Chloe's age is 30 years or 365 months or 11102 days"
1516
assert age_calculator(name, age) == expect_output
1617

18+
1719
def test_age_calculator_negative_age():
1820
"""
1921
Tests the age_calculator function for negative age input

projects/Calculate Age/tests/test_utilize_date.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
def test_judge_leap_year():
66
"""
7-
judge_leap_year function tests whether a given year is a leap year.
7+
judge_leap_year function tests whether a given year is a leap year.
88
9-
A leap year is divisible by 4 and, if divisible by 100, must also be divisible by 400.
9+
A leap year is divisible by 4 and, if divisible by 100, must also be divisible by 400.
1010
"""
1111
assert judge_leap_year(2000) == True
1212
assert judge_leap_year(2008) == True

projects/Chat-GPT-Discord-Bot/Chat_GPT_Function.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,44 @@
66

77
gpt_api_key = os.getenv("GPT_API_KEY")
88

9+
910
def gpt(model: str, prompt: str, sys_prompt: str, temp: float):
10-
client = OpenAI(api_key= gpt_api_key)
11+
client = OpenAI(api_key=gpt_api_key)
1112
response = client.chat.completions.create(
12-
model = model,
13+
model=model,
1314
messages=[
14-
{
15-
"role": "system",
16-
"content": sys_prompt
17-
},
18-
{
19-
"role": "user",
20-
"content": prompt
21-
}
15+
{"role": "system", "content": sys_prompt},
16+
{"role": "user", "content": prompt},
2217
],
23-
temperature = temp,
18+
temperature=temp,
2419
# max_tokens=64,
25-
top_p=1
20+
top_p=1,
2621
)
2722
output = response.choices[0].message.content.strip()
2823
return output
2924

25+
3026
def dalle3(prompt: str, quality: str, size: str, style: str):
31-
client = OpenAI(api_key= gpt_api_key)
27+
client = OpenAI(api_key=gpt_api_key)
3228
response = client.images.generate(
33-
model = "dall-e-3",
34-
prompt = prompt,
35-
size = size,
36-
quality = quality,
37-
style = style,
29+
model="dall-e-3",
30+
prompt=prompt,
31+
size=size,
32+
quality=quality,
33+
style=style,
3834
n=1,
39-
)
35+
)
4036
image_url = response.data[0].url
4137
return image_url
4238

39+
4340
def dalle2(prompt: str, size: str):
44-
client = OpenAI(api_key= gpt_api_key)
41+
client = OpenAI(api_key=gpt_api_key)
4542
response = client.images.generate(
46-
model = "dall-e-2",
47-
prompt = prompt,
48-
size = size,
43+
model="dall-e-2",
44+
prompt=prompt,
45+
size=size,
4946
n=1,
50-
)
47+
)
5148
image_url = response.data[0].url
52-
return image_url
49+
return image_url

0 commit comments

Comments
 (0)