Write a function isRed() that accepts a string parameter and looks for the presence of the word ‘red’ in the string. If it is found, return boolean True otherwise False. Finally output the result of calling the function with the value in text.

Respuesta :

ijeggs

Answer:

Using the Python Programming Language:

def isRed(myString):

   if "red" in myString:

       return True

   else:

       return False

Explanation:

The function definition is given above. To output the result of calling this function, we declare a string variable and call the function inside a print statement. See the two lines of code below:

myString= "My house is coloured red"

print (isRed(myString))

Notice that we defined the function called isRed to receive a string as a parameter, Then using the in keyword with an if statement, we check for the presence of the word 'red' in the string that is passed as argument to the function, the function will then return True if the word 'red' is present or False if it is not.

CPED

Answer:

Following is the code for the function isRed() that works according to given scenario:

import sys

text = sys.argv[1]

def isRed(text):

if(text.find('red')!=-1):

return True

else:

return False

Explanation:

  1. First of all the input is taken from the user through command line using statement text = sys.argv[1]
  2. The function named isRed is defined by putting text variable as parameter to it.
  3. The function uses if else statement and says if the input text contains red then return True as the output to the function.
  4. Otherwise if 'red' is not found then the output of the function will be False.

i hope it will help you!