Python

 

 

Manage and view events on your calendar

Introduction

In this project, we will create a simple Calendar App that allows users to add and view events for specific dates. The app will be developed using Python, and it will make use of basic data structures to manage events. The goal of this program is to allow users to store, retrieve, and display events for given dates on their calendar.

Objective

  • Create a calendar to store events.
  • Allow users to add events for specific dates.
  • Allow users to view events for a selected date.
  • Implement the program in Python with a simple text-based interface.

Python Code for Calendar App

# Simple Calendar App in Python

import calendar

# Dictionary to store events
events = {}

def add_event(date, event):
    # Adds an event to the specified date
    if date in events:
        events[date].append(event)
    else:
        events[date] = [event]
    print(f"Event added on {date}: {event}")

def view_events(date):
    # Displays events for the specified date
    if date in events:
        print(f"Events on {date}:")
        for event in events[date]:
            print(f"- {event}")
    else:
        print(f"No events found on {date}.")

def show_menu():
    # Displays the menu and handles user input
    print("\n--- Calendar App Menu ---")
    print("1. Add Event")
    print("2. View Events")
    print("3. Exit")

def main():
    # Main function to run the app
    while True:
        show_menu()
        choice = input("Choose an option: ")

        if choice == '1':
            date = input("Enter the date (YYYY-MM-DD): ")
            event = input("Enter the event description: ")
            add_event(date, event)
        elif choice == '2':
            date = input("Enter the date (YYYY-MM-DD) to view events: ")
            view_events(date)
        elif choice == '3':
            print("Exiting Calendar App.")
            break
        else:
            print("Invalid choice. Please select a valid option.")

# Run the app
if __name__ == "__main__":
    main()

Explanation of the Program Structure

The program is divided into multiple sections:

  • add_event(date, event): This function takes a date and an event description as input and adds the event to the dictionary for that date.
  • view_events(date): This function displays all events for a given date by retrieving them from the dictionary.
  • show_menu(): This function displays the menu of options to the user, including options to add an event, view events, or exit the app.
  • main(): This is the main function that runs the app. It displays the menu, accepts user input, and calls the appropriate function based on user choices.

How to Run the Program

To run the Calendar App, follow these steps:

  1. Ensure you have Python installed on your machine. You can download it from here.
  2. Create a new Python file (e.g., calendar_app.py) and paste the provided code into the file.
  3. Open a terminal or command prompt and navigate to the directory where the Python file is saved.
  4. Run the program by typing python calendar_app.py in the terminal or command prompt.
  5. Follow the on-screen instructions to add or view events.
© 2025 Learn Programming. All rights reserved.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)