Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class interpret():
- def Init(self, s, long_mode = True):
- global accumulator
- try:
- accumulator = accumulator
- except:
- accumulator = 0
- do = {"H": lambda: self.hello(),
- "Q": lambda: self.quine(),
- "9": lambda: self.beers(long_mode),
- "+": lambda: self.incre(),}
- if len(s) > 1:
- raise Exception("Too many instructions.")
- return
- for i in list(s):
- if i not in ["H", "Q", "9", "+"]:
- raise Exception("Unrecognized Instruction")
- return
- return str(do[s]())+"\n"
- def hello(self):
- return "Hello, World!"
- def quine(self):
- return "Q"
- def beers(self, long_mode):
- song = []
- if long_mode:
- for i in range(1, 98):
- i = 100-i
- song.append(str(i)+" bottles of beer on the wall, "+str(i)+" bottles of beer!\nTake one down, pass it around, "+str(i-1)+" bottles of beer on the wall!\n")
- song.append("2 bottles of beer on the wall, 2 bottles of beer!\nTake one down, pass it around, 1 bottle of beer on the wall!\n")
- song.append("1 bottle of beer on the wall, 1 bottle of beer!\nTake it down, pass it around, no more bottles of beer on the wall!\n")
- song.append("No more bottles of beer on the wall, no more bottles of beer!\nGo to the store and buy some more, 99 bottles of beer on the wall!")
- else:
- song.append("99 bottle of beer on the wall, 99 bottles of beer!\nTake one down, pass it around, 98 bottles of beer on the wall!\n")
- song.append("[...]\n")
- song.append("1 bottle of beer on the wall, 1 bottle of beer!\nTake it down, pass it around, no more bottles of beer on the wall!\n")
- song.append("No more bottles of beer on the wall, no more bottles of beer!\nGo to the store and buy some more, 99 bottles of beer on the wall!")
- return '\n'.join(song)
- def incre(self):
- global accumulator
- accumulator += 1
- return accumulator
- if __name__ == "__main__":
- while True:
- print(interpret().Init(input("> "), False))
Advertisement
Add Comment
Please, Sign In to add comment