+ 1
Can you guys help me check where my codes has gone wrong?Thanks in advance. The question is in the description..
You need to check whether the string is a smiley face. If yes – output 1, otherwise – 0. Smiley: Eyes is one of ":" ";" ">:", nose "-" either one or none at all, mouth is one of "{", "}", "[", "]", "(", ")", "p" at least once. One type may be repeated as many times as you want. All symbols go precisely in the listed order, smiley does not contain any other symbols. Input data String with length up to 100 symbols, consisting of uppercase and lowercase letters of the Latin alphabet and various characters. Output data Output 1, if the given string is a smiley. Otherwise output 0. https://code.sololearn.com/ct3cyhS8L959/?ref=app
7 Respostas
+ 4
pattern = r"(:|;|(>:))\-?(\{+|\}+|\[+|\]+|\(+|\)+|p+)quot;
Last try. Must work!
+ 9
mouths and nose are regex metacharacters so you have to escape them
+ 3
Do sth like this:
pattern=r"(:|;|(>:))\-?(\{|\}|\[|\]|\(|\)|p)+quot;
This should work
PS. note the backslashes
+ 2
It works! Thank youso much😄
+ 1
I have escaped all the regex metacharacters but it still won't work for some cases like:()which the output should be 0 but my code would give 1...do u guys have any ideas about how to make sure that the mouth are all the same characters if there are more than 1 characters in the mouth portion(my code are not supposed to accept :()or:[) these kind of things)
+ 1
So, do sth like this:
pattern=r"(:|;|(>:))\-?(\{|\}|\[|\]|\(|\)|p)quot;
This should work
PS. note removing the plus sing at the end of regex
0
then cases like :))) will not pass..but they are still considereda smiley face