1
1
import re
2
2
3
- def recite (start_verse , end_verse ):
4
-
5
-
6
- Dictionary2D = {
7
- 12 :["twelfth" , "twelve" ],
8
- 11 :["eleventh" , "eleven" ],
9
- 10 :["tenth" , "ten" ],
10
- 9 :["ninth" , "nine" ],
11
- 8 :["eigth" , "eigth" ],
12
- 7 :["seventh" , "seven" ],
13
- 6 :["sixth" , "six" ],
14
- 5 :["fifth" , "five" ],
15
- 4 :["fourth" , "four" ],
16
- 3 :["third" , "three" ,"French Hens, " ],
17
- 2 :["second" , "two" ,"Turtle Doves, " ],
18
- 1 :["first" , "and a" , "Partridge in a Pear Tree." ]
19
- }
20
-
21
- # "On the twelfth day of Christmas my true love gave to me: "
22
- # "twelve Drummers Drumming, "
23
- # "eleven Pipers Piping, "
24
- # "ten Lords-a-Leaping, "
25
- # "nine Ladies Dancing, "
26
- # "eight Maids-a-Milking, "
27
- # "seven Swans-a-Swimming, "
28
- # "six Geese-a-Laying, "
29
- # "five Gold Rings, "
30
- # "four Calling Birds, "
31
- # "three French Hens, "
32
- # "two Turtle Doves, "
33
- # "and a Partridge in a Pear Tree."
34
- song = {}
35
- song [1 ] = 'Partridge in a Pear Tree'
36
- song [2 ] = 'Turtle Doves'
37
- song [3 ] = 'French Hens'
38
- song [4 ] = 'Calling Birds'
39
- song [5 ] = 'Gold Rings'
40
- song [6 ] = 'Geese-a-Laying'
41
- song [7 ] = 'Swans-a-Swimming'
42
- song [8 ] = 'Maids-a-Milking'
43
- song [9 ] = 'Ladies Dancing'
44
- song [10 ] = 'Lords-a-Leaping'
45
- song [11 ] = 'Pipers Piping'
46
- song [12 ] = 'Drummers Drumming'
47
-
48
- numbers = {}
49
- numbers [1 ] = 'a'
50
- numbers [2 ] = 'two'
51
- numbers [3 ] = 'three'
52
- numbers [4 ] = 'four'
53
- numbers [5 ] = 'five'
54
- numbers [6 ] = 'six'
55
- numbers [7 ] = 'seven'
56
- numbers [8 ] = 'eight'
57
- numbers [9 ] = 'nine'
58
- numbers [10 ] = 'ten'
59
- numbers [11 ] = 'eleven'
60
- numbers [12 ] = 'twelve'
61
-
62
- nth = {}
63
- nth [1 ] = 'first'
64
- nth [2 ] = 'second'
65
- nth [3 ] = 'third'
66
- nth [4 ] = 'fourth'
67
- nth [5 ] = 'fifth'
68
- nth [6 ] = 'sixth'
69
- nth [7 ] = 'seventh'
70
- nth [8 ] = 'eighth'
71
- nth [9 ] = 'ninth'
72
- nth [10 ] = 'tenth'
73
- nth [11 ] = 'eleventh'
74
- nth [12 ] = 'twelfth'
3
+ nth = {
4
+ 1 : "first" ,
5
+ 2 : "second" ,
6
+ 3 : "third" ,
7
+ 4 : "fourth" ,
8
+ 5 : "fifth" ,
9
+ 6 : "sixth" ,
10
+ 7 : "seventh" ,
11
+ 8 : "eighth" ,
12
+ 9 : "ninth" ,
13
+ 10 : "tenth" ,
14
+ 11 : "eleventh" ,
15
+ 12 : "twelfth"
16
+ }
17
+
18
+ lines = [
19
+ "twelve Drummers Drumming" ,
20
+ "eleven Pipers Piping" ,
21
+ "ten Lords-a-Leaping" ,
22
+ "nine Ladies Dancing" ,
23
+ "eight Maids-a-Milking" ,
24
+ "seven Swans-a-Swimming" ,
25
+ "six Geese-a-Laying" ,
26
+ "five Gold Rings" ,
27
+ "four Calling Birds" ,
28
+ "three French Hens" ,
29
+ "two Turtle Doves" ,
30
+ "and a Partridge in a Pear Tree"
31
+ ]
75
32
33
+ def recite (start_verse , end_verse ):
34
+ return [recite_verse (line ) for line in range (start_verse , end_verse + 1 )]
76
35
77
- print ("On the " + nth [end_verse ] + " day of Christmas my true love gave to me: " )
78
-
79
- for k , v in song .items ()[::- 1 ]:
80
- if song [k ] > 1
81
- print (numbers [k ] + " " + v )
82
-
83
-
84
- if end_verse > 1 :
85
- end_line = "and"
86
- print (end_line + " " + numbers [1 ] + " " + "Partridge in a Pear Tree" )
87
- else :
88
- print (numbers [1 ] + " " + "Partridge in a Pear Tree" )
89
-
90
- print ("######" )
91
- pass
36
+ def recite_verse (line ):
37
+ return f"On the { nth [line ]} day of Christmas my true love gave to me: " + re .sub ("^and " , "" , ", " .join (lines [12 - line :12 ])) + "."
0 commit comments