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...
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: Write a function called linsolve() that will be useful in categorizing...
Write the following Python script: Write a function called linsolve() that will be useful in categorizing and solving linear algebra problems. The function will have up to three parameters: • A required 2D array representing the coefficient matrix of a linear algebra equation, • A required 1D or 2D array representing the right-side constants of a linear algebra equations, and • An optional parameter used to determine which condition number to use in determining the condition of the system. The...
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 a python script to calculate 401k with compounding interest
write a python script to calculate 401k with compounding interest
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 script or function in Python that approximates the solution to the system ??⃗=?⃗⃗ using...
Write a script or function in Python that approximates the solution to the system ??⃗=?⃗⃗ using the Jacobi Method. The inputs should be an nxn matrix A, an n-dimensional vector?⃗⃗, a starting vector ?⃗0,an error tolerance ?, and a maximum number of iterations N. The outputs should be either an approximate solution to the system??⃗=?⃗⃗ or an error message, along with the number of iterations completed. Additionally, it would be wise to build in functionality that allows you to optionally...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT