Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions Age Calculator/calculate.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import time
from calendar import isleap

def judge_leap_year(year):
if isleap(year):
return True
else:
return False
# Check if a year is a leap year
def judge_leap(year: int) -> bool:
return isleap(year)

def month_days(month, leap_year):
# Return number of days in a month, considering leap years
def month_days(month: int, leap_year: bool) -> int:
if month in [1, 3, 5, 7, 8, 10, 12]:
return 31
elif month in [4, 6, 9, 11]:
return 30
elif month == 2 and leap_year:
return 29
elif month == 2 and (not leap_year):
else:
return 28


# User input
name = input("Please enter your name: ")
age = input("Please enter your age: ")
age = int(input("Please enter your age: "))

localtime = time.localtime(time.time())

year = int(age)
Expand All @@ -29,16 +29,25 @@ def month_days(month, leap_year):
begin_year = int(localtime.tm_year) - year
end_year = begin_year + year

# Count days in past years
for y in range(begin_year, end_year):
if (judge_leap_year(y)):
day = day + 366
if judge_leap(y):
day += 366
else:
day = day + 365
day += 365

leap_year = judge_leap_year(localtime.tm_year)
# Add days from current year
leap_year = judge_leap(localtime.tm_year)
for m in range(1, localtime.tm_mon):
day = day + month_days(m, leap_year)

day = day + localtime.tm_mday
print("\n\t%s's age is %d years or " % (name, year), end="")
print("%d months or %d days" % (month, day))
day += month_days(m, leap_year)

# Approximate breakdown (ignores time of day)
hours = day * 24
minutes = hours * 60
seconds = minutes * 60
Comment on lines +44 to +47
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation includes the current day (localtime.tm_mday) which represents a partial day, but then multiplies by 24 hours as if it were complete days. This creates inaccurate hour/minute/second calculations. Consider excluding the current partial day or adjusting the calculation to account for the actual time of day.

Suggested change
# Approximate breakdown (ignores time of day)
hours = day * 24
minutes = hours * 60
seconds = minutes * 60
# More accurate breakdown (includes time of day)
hours = day * 24 + localtime.tm_hour
minutes = hours * 60 + localtime.tm_min
seconds = minutes * 60 + localtime.tm_sec

Copilot uses AI. Check for mistakes.


print(f"\nHello {name}, you are approximately:")
print(f" {day:,} days")
print(f" {hours:,} hours")
print(f" {minutes:,} minutes")
print(f" {seconds:,} seconds old!")
39 changes: 33 additions & 6 deletions Digital Clock/main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
from time import strftime
from tkinter import Label, Tk
from tkinter import Label, Tk , Button

window = Tk()
window.title("Digital Clock")
window.geometry("300x100")
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The window height of 100px may be insufficient to accommodate the new date label and toggle button. Consider increasing the height to ensure all elements are visible without overlapping.

Suggested change
window.geometry("300x100")
window.geometry("300x180")

Copilot uses AI. Check for mistakes.

window.configure(bg="green")
window.resizable(False, False)

use_24h = True

clock_label = Label(
window, bg="black", fg="green", font=("Arial", 30, "bold"), relief="flat"
)
clock_label.place(x=50, y=50)
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using both place() and pack() geometry managers in the same window can cause layout conflicts. The clock_label uses place() while date_label and fmt_btn use pack(). Consider using a consistent geometry manager throughout.

Suggested change
clock_label.place(x=50, y=50)
clock_label.pack(pady=(10, 0), anchor="center")

Copilot uses AI. Check for mistakes.



date_label = Label(
window, bg="black", fg="white", font=("Arial", 14)
)
date_label.pack(pady=(0, 10), anchor="center")



def toggle_format(_evt=None):
global use_24h
use_24h = not use_24h
fmt_btn.config(text="Switch to 24-hour" if not use_24h else "Switch to 12-hour")

fmt_btn = Button(window, text="Switch to 12-hour", command=toggle_format)
fmt_btn.pack(pady=(0, 8))
window.bind("<f>", toggle_format) # press 'f' to toggle



def update_label():
current_time = strftime("%H: %M: %S\n %d-%m-%Y ")
clock_label.configure(text=current_time)
clock_label.after(80, update_label)
clock_label.pack(anchor="center")

if use_24h:
time_text = strftime("%H:%M:%S")
else:
# strip leading zero in 12h mode for a cleaner look
time_text = strftime("%I:%M:%S %p").lstrip("0")
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using lstrip('0') removes all leading zeros from the entire string, which could incorrectly strip zeros from minutes or seconds (e.g., '10:05:02' becomes '1:5:2'). Use strftime('%#I:%M:%S %p') on Windows or strftime('%-I:%M:%S %p') on Unix systems to remove only the leading zero from hours.

Copilot uses AI. Check for mistakes.

clock_label.configure(text=time_text)
date_label.configure(text=strftime("%A, %b %d, %Y"))
window.after(1000, update_label)

update_label()
window.mainloop()
window.mainloop()