Advertisement
GamerBhai02

Python Exp 5

Mar 27th, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | Source Code | 0 0
  1. from datetime import datetime
  2. import time
  3.  
  4. def show_current_time():
  5.     now = datetime.now()
  6.     print("Current Date and Time:",now.strftime("%Y-%m-%d %H:%M:%S"))
  7. def set_alarm(hour,minute):
  8.     print(f"Alarm set for {hour}:{minute}. Waiting to ring...")
  9.     while True:
  10.         now = datetime.now()
  11.         if now.hour == hour and now.minute == minute:
  12.             print("It is time to wake up!!")
  13.             print("📢📢📢📢📢📢📢📢📢")
  14.             break
  15.         time.sleep(10)
  16. def calc_date_diff(date1,date2):
  17.     d1 = datetime.strptime(date1,"%Y-%m-%d")
  18.     d2 = datetime.strptime(date2,"%Y-%m-%d")
  19.     diff = abs((d2-d1).days)
  20.     print(f"The difference between {date1} and {date2} is {diff} days.")
  21.  
  22. print("Date and Time Application")
  23. while True:
  24.     print("1. Show Current Date & Time")
  25.     print("2. Set an Alarm")
  26.     print("3. Calculate Date Difference")
  27.     print("4. Exit")
  28.     choice = input("Enter your choice:")
  29.     if (choice=='1'):
  30.         show_current_time()
  31.     elif (choice=='2'):
  32.         hour = int(input("Enter hour (24-hour format):"))
  33.         minute = int(input("Enter minute:"))
  34.         set_alarm(hour,minute)
  35.     elif (choice=='3'):
  36.         date1 = input("Enter 1st date (YYYY-MM-DD):")
  37.         date2 = input("Enter 2nd date (YYYY-MM-DD):")
  38.         calc_date_diff(date1,date2)
  39.     elif (choice=='4'):
  40.         print("Exiting")
  41.         break
  42.     else:
  43.         print("Invalid choice. Please try again.")
Tags: exp5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement