asked 63.4k views
3 votes
One thing we might want to know, given an input to a chatbot, is if the input is a question.

We are going to use a very simple heuristic to check this: we will consider any input that has a question mark ('?') in it to be a question.
To do so, write a function called is_question.
This function should have the following inputs, outputs, and internal procedures:
Input(s): input_string - string
Output(s): output - boolean
Procedure(s): if there is a '?' in input_string, set output to True
otherwise, set output to False.
return output

asked
User Dorsh
by
7.6k points

1 Answer

1 vote

Answer:

Following are the code to this question:

def is_question(input_string): # defining method is_question

output = '?' in input_string # checking question mark symbol in value

return output #return value

input_string = input('Enter any string value: ') # defining variable input_string to input value

print (is_question(input_string)) # call method and print return value

Output:

Enter any string value: what is your name?

True

Step-by-step explanation:

In the given python program code, a method "is_question" is declared, which accepts an "input_string" value in its parameter.

  • Inside the method, an output variable is used, that search question symbol in the parameter value and return its value.
  • In the next step, the input_string variable is declared, which uses the input method to accepts string value and passes into method calling time and print its return value.
answered
User Jitendra Vyas
by
8.2k points