{ "metadata": { "name": "Chapter XIV" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 14: More on data types" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Program 14.1, Page number: 323" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "def main():\n", "\n", " #Declaring an Enumerator \n", " def enum(**enums):\n", " return type('Enum',(),enums)\n", "\n", " #Defining an Enumerator\n", " month=enum(january=1,february=2,march=3,april=4,may=5,june=6,july=7,\\\n", " august=8,september=9,october=10,november=11,december=12)\n", " days=0\n", "\n", " print(\"Enter month number:\")\n", " aMonth=8 #aMonth=raw_input()\n", "\n", " #Calculations\n", " if(int(aMonth)==month.january or int(aMonth)==month.march or \\\n", " int(aMonth)==month.may or int(aMonth)==month.july or \\\n", " int(aMonth)==month.august or int(aMonth)==month.october or int(aMonth)==month.december):\n", " days=31\n", "\n", " elif(int(aMonth)==month.april or int(aMonth)==month.june or \\\n", " int(aMonth)==month.september or int(aMonth)==month.november):\n", " days=30\n", " elif(int(aMonth)==month.february):\n", " days=28\n", " else:\n", " print(\"bad month number\")\n", " days=0\n", "\n", " #Result\n", " if(days!=0):\n", " print(\"Number of days is {0}\".format(days))\n", " if(int(aMonth)==month.february):\n", " print(\"...or 29 if it's a leap year\")\n", "\n", "\n", "if __name__=='__main__':\n", " main()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Enter month number:\n", "Number of days is 31\n" ] } ], "prompt_number": 2 } ], "metadata": {} } ] }