1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
{
"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": {}
}
]
}
|