Question

In: Computer Science

Write the following Python script: Pikachu is a well-known character in the Pokemon anime series. Pikachu...

Write the following Python script:

Pikachu is a well-known character in the Pokemon anime series. Pikachu can speak, but only 3 syllables: "pi", "ka", and "chu". Therefore Pikachu can only pronounce strings that can be created as a concatenation of one or more syllables he can pronounce. For example, he can pronounce the words "pikapi" and "pikachu".

You are given a String word. Your task is to check whether Pikachu can pronounce the string. If the string can be produced by concatenating copies of the strings "pi", "ka", and "chu", return "YES" (quotes for clarity). Otherwise, return "NO".

Constraints:

  • word contains between 1 and 50 characters, inclusive
  • each character of word will be a lower-case letter 'a'-'z'

Check your work with these examples:

-------------------------------------------------------

word = "kpia"

Returns: "NO"

-------------------------------------------------------

word = "chuchucpihu"

Returns: "NO"

-------------------------------------------------------

word = "pikapi"

Returns: "YES"

"pikapi" = "pi" + "ka" + "pi", so Pikachu can say it.

-------------------------------------------------------

word = "pipikachu"

Returns: "YES"

This time we have "pipikachu" = "pi" + "pi" + "ka" + "chu", so Pikachu can say it as well.

-------------------------------------------------------

word = "pikaqiu"

Returns: "NO"

Pikachu can't say "pikaqiu" since 'q' does not appear in "pi", "ka", or "chu".

-------------------------------------------------------

word = "chupikachupipichu"

Returns: "YES"

-------------------------------------------------------

word = "duke"

Returns: "NO"

Solutions

Expert Solution

SCREENSHOT OF THE PYTHON CODE :

PYTHON CODE :

def search(string):
while True:
if string.endswith("pi"): # if pi found, then remove pi
string = string[:-(len("pi"))]
continue
if string.endswith("ka"): # if ka found remove ka
string = string[:-(len("ka"))]
continue
if string.endswith("chu"): # if chu found remove cha
string = string[:-(len("chu"))]
continue
else:
break
if string == "":
return "YES"
return "NO"

print("Result :", search(input("Enter the string : "))) # READ THE STRING

SAMPLE OUTPUTS :


Related Solutions

Using Python write the following script as well as using comments By considering the details below,...
Using Python write the following script as well as using comments By considering the details below, write a class that will work out the body mass index for specific values of weight and height. The design of the actual class is shown below: bmi -weight:float -height:float -bmi:float +set_weight(weight:float) +set_height(height:float) +calc_bmi() +get_bmi():float specific designs of the methods are shown below: set_weight set the weight attribute to the value in the parameter weight set_height set the height attribute to the value in...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
Write the following Python script: Problem Statement A string X is an anagram of string Y...
Write the following Python script: Problem Statement A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which...
Write a Python script that takes an input image and output's the name of the dominant...
Write a Python script that takes an input image and output's the name of the dominant color in that image(i.e. red, green, blue).  
PYTHON: Write a script that imports the functions in the module below and uses all of...
PYTHON: Write a script that imports the functions in the module below and uses all of the functions. import math def _main():     print("#" * 28, "\n", "Testing...1, 2, 3...testing!\n", "#" * 28, "\n", sep="")     f = -200     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     f = 125     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     c = 0     print("{:.2f} C is {:.2f} F".format(c, c2f(c)))     c = -200     print("{:.2f} C is {:.2f} F".format(c, c2f(c))) def f2c(temp):     #Converts Fahrenheit tempature to Celcius     if temp <...
In this assignment, you will write a Python script to increase the population of each city...
In this assignment, you will write a Python script to increase the population of each city in the world_x database by 10% (rounded). First, add a new column to the "world_x" city table using the following MySQL command: ALTER TABLE `world_x`.`city` ADD COLUMN `Population` DOUBLE NULL DEFAULT NULL AFTER `Info`; The existing population data are stored as JSON datatype in the city table in a field named Info. You learned about JSON data types in Module 2. To obtain the...
Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT