1# Jingle Bells - Example for illustrative purposes only.
2
3import smartpy as sp
4
5
6@sp.module
7def main():
8 lyrics = {
9 0: "Dashing through the snow",
10 1: "In a one-horse open sleigh",
11 2: "O'er the fields we go",
12 3: "Laughing all the way",
13 4: "",
14 5: "Bells on bob tail ring",
15 6: "Making spirits bright",
16 7: "What fun it is to ride and sing",
17 8: "A sleighing song tonight!",
18 9: "",
19 10: "Jingle bells, jingle bells,",
20 11: "Jingle all the way.",
21 12: "Oh! what fun it is to ride",
22 13: "In a one-horse open sleigh.",
23 14: "",
24 15: "Jingle bells, jingle bells,",
25 16: "Jingle all the way;",
26 17: "Oh! what fun it is to ride",
27 18: "In a one-horse open sleigh.",
28 }
29
30 class JingleBells(sp.Contract):
31 def __init__(self):
32 self.private.lyrics = lyrics
33 self.data.rules = [
34 "Please sing as much as you wish!",
35 "Happy Holidays from the SmartPy team!",
36 ]
37 self.data.played = 0
38 self.data.verse = 0
39 self.data.current = ""
40
41 @sp.entrypoint
42 def sing(self, params):
43 for i in range(0, params.verses):
44 if self.data.verse == len(lyrics):
45 self.data.played += 1
46 self.data.current = ""
47 self.data.verse = 0
48 if self.data.current != "":
49 self.data.current += "\n"
50 self.data.current += self.private.lyrics[self.data.verse]
51 self.data.verse += 1
52
53
54if "main" in __name__:
55
56 @sp.add_test()
57 def test():
58 scenario = sp.test_scenario("JingleBells", main)
59 c1 = main.JingleBells()
60 scenario.h1("Jingle Bells")
61 scenario += c1
62 for i in range(0, 10):
63 c1.sing(verses=1)
64 c1.sing(verses=6)
65 c1.sing(verses=100)