Tuesday, 9 May 2017

Menu based Basic Calender Management System

Menu based Basic Calendar Management System

We will be working on super simple, hourly based, basic calendar management system. We will be using dictionary, data structure provided by python.


#function to display all events in calendar

def event_disp():
   system('clear')
   print ("\n\n#####################################\n\n")
   print ("Time : \t\tEvent")
   for key, value in hour.items():
      print key, "\t\t" + value
   print ("\n\n#####################################\n\n")
   return

#function to display main menu and taking user inputs

def disp():

   # using system in built command for clearing screen

   system('clear')

   print ("\n\n#####################################\n\n")
   print ("\t1. Add event to calander")
   print ("\t2. Remove event from calander")
   print ("\t3. View Events from yout calander")
   print ("\n\n#####################################\n\n")

   userInput = int(input("Choose 1,2 or 3 for options:\t"))

   if userInput == 1:
      inputTime = int(raw_input("Enter time in format (hh):\t"))
      if inputTime >= 24 or inputTime < 0:
         print "Time is only supported from 00 to 23 hours"
      else:

         #checking if the event already exist for the same time.

         if not hour.get(inputTime):
            inputEvent = raw_input("Enter event to store:\t")
hour[inputTime] = inputEvent
         else:
            print ("Event is already schedule for this time.")
   elif userInput == 2:
      event_disp()
      inputTime = int(raw_input("Enter the time you want to clear:\t"))

      #deleting the event using key from dictionary 

      del hour[inputTime]

      event_disp()

   elif userInput == 3:
      event_disp()

   cont=raw_input("Back to main menu(y/n):\t")
   if cont == 'y' or cont == 'yes':
      disp()
   else:
     exit()

#importing system from os, for clear command we used earlier

from os import system

#Adding some random input for our dictionary.

hour = {11:"This is sparta", 12 : "Sleep"}

disp()


Screenshots:

1 Main screen and adding event


2 View Events



3 Removing event


4 List after removing event

No comments:

Post a Comment