You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
8.2 KiB
8.2 KiB
balanced emoticons: a playful critical code study¶
this is written for the doggies and kitties in the anthropo-sphere
methods implemented were referred with caution to the following:
https://www.geeksforgeeks.org/python-program-check-string-palindrome-not/
more cat emoticons: https://www.copyandpastesymbols.net/emoticon/cat-emoticons.html
In [21]:
# palindrome method # slice the string backwards def isBalanced(s): if s == s[::-1]: print("{} is a balanced emoticon!".format(s)) else: print("{} is not a balanced emoticon, try another one?".format(s)) # try a simple emoticon suprised_f = "0_0" isBalanced(suprised_f)
0_0 is a balanced emoticon!
In [22]:
cat_hearty = "(*♥^•ﻌ•^♥*)" isBalanced(cat_hearty)
(*♥^•ﻌ•^♥*) is not a balanced emoticon, try another one?
In [23]:
#strip the opening brackets and closing brackets s_cat_hearty = cat_hearty.strip("()") isBalanced(s_cat_hearty)
*♥^•ﻌ•^♥* is a balanced emoticon!
In [24]:
#update the isBalanced method def isBalanced(s): if s == s[::-1]: print("{} is a balanced emoticon!".format(s)) else: s_strip = s.strip("()") if s_strip == s_strip[::-1]: print("{} is a balanced emoticon!".format(s)) else: print("{} is not a balanced emoticon, try another one?".format(s))
In [25]:
#try with the updated method isBalanced(cat_hearty)
(*♥^•ﻌ•^♥*) is a balanced emoticon!
In [27]:
# try a list of kitty emoji strings c_strings_l = ["ლ(●ↀωↀ●)ლ","(゚∀゚)","(=^・ω・^=)","(^・x・^)"] for string in c_strings_l: isBalanced(string) print()
ლ(●ↀωↀ●)ლ is not a balanced emoticon, try another one? (゚∀゚) is a balanced emoticon! (=^・ω・^=) is a balanced emoticon! (^・x・^) is a balanced emoticon!
In [28]:
d_strings_l = ["▼・ᴥ・▼","U・ﻌ・U"," υ´• ﻌ •`υ","ᐡ ・ ﻌ ・ ᐡ"] for string in d_strings_l: isBalanced(string) print()
▼・ᴥ・▼ is a balanced emoticon!
U・ﻌ・U is a balanced emoticon!
υ´• ﻌ •`υ is not a balanced emoticon, try another one?
ᐡ ・ ﻌ ・ ᐡ is a balanced emoticon!
In [29]:
#why would it not be? wide_eyes = "ლ(●ↀωↀ●)ლ" r_wide_eyes = wide_eyes[::-1] s_r_wide_eyes = r_wide_eyes.strip("()") print(s_r_wide_eyes)
ლ)●ↀωↀ●(ლ
in the kitty emoji, the strip method won't work now since it only applies to stripping away leading or trailing chars. therefore the method is buggy, as the pair of brackets are not matching. similarily, in the doggie emoji, the pair of ticks that make up the eyebrows are not assigned as matching.
In [30]:
# bonus program # printing emoticon trees # the program will fail # ******************************* # * run a half loop comparison * # ******************************* def isPalindrome(str): # Run loop from 0 to len/2 for i in range(0, int(len(str)/2)): if str[i] != str[len(str)-i-1]: return False return True # main function s = " υ´• ﻌ •`υ" ans = isPalindrome(s) if (ans): print("Half loop comparison says passing test") else: print("Half loop comparison says failing test") # ******************************* # * move emoticon to a new var * # ******************************* # Python program to check # if a string is palindrome # or not x = "υ´• ﻌ •`υ" w = "" z = "" y = "" print("it's going to print half a doggie tree watch out") for i in x: w = i + w print(w)
Half loop comparison says failing test it's going to print half a doggie tree watch out υ ´υ •´υ •´υ ﻌ •´υ ﻌ •´υ • ﻌ •´υ `• ﻌ •´υ υ`• ﻌ •´υ
now the eyebrows are flipped and doggie's mood changed, the ticks didn't match the original and it failed the test.
In [31]:
#add indent to make the tree's other half indent = " " counter = len(w) for i in w: z = i + z indent = indent * counter print(indent + z) counter = counter - 1 indent = " "
υ `υ •`υ •`υ ﻌ •`υ ﻌ •`υ • ﻌ •`υ ´• ﻌ •`υ υ´• ﻌ •`υ
In [ ]: