I tried PPAP using a special method of Python.
I used __add__
and __mul__
to add and multiply strings.
PPAP
import re
## PPAP class
class PPAP(str):
def __add__(self, other):
self.print_materials(other)
result = "{1}-{0}".format(self, other)
print("Oh, {0}!".format(result))
return PPAP(result)
def __mul__(self, other):
match = re.search("(\w+)-(\w+)", other)
mate_1, mate_2 = match.group(1), match.group(2)
result = "{0}-{1}-{2}".format(mate_2, mate_1, self)
print("{0}!!".format(result))
return PPAP(result)
def print_materials(self, other):
print("I have a {0}~".format(self))
print("I have a {0}~".format(other))
#Run PPAP
pen = PPAP("pen")
apple = PPAP("apple")
pineapple = PPAP("pineapple")
print("---(1st Phase)---")
result_1 = pen + apple
print("---(2nd Phase)---")
result_2 = pen + pineapple
print("---(Last Phase)---")
result_1 * result_2
result
---(1st Phase)---
I have a pen~
I have a apple~
Oh, apple-pen!
---(2nd Phase)---
I have a pen~
I have a pineapple~
Oh, pineapple-pen!
---(Last Phase)---
pen-pineapple-apple-pen!!
Recommended Posts