write a program that reads a one-line sentence as input and then displays the following response: if the sentence ends with a question mark (?) and the input contains an even number of characters, display the word Yes. If the sentence ends with a question mark and the input contains an odd number of characters, display the word No. If the sentence ends with an exclamation point (!), display the word Wow. In all other cases, display the words You always say followed by the input string enclosed in quotes. Your output should all be on one line. Be sure to note that in the last case, your output must include quotation marks around the echoed input string. In all other cases, there are no quotes in the output. Your program does not have to check the input to see that the user has entered a legitimate sentence.

Respuesta :

We use if-else structure to check if the sentence meets the requirements for each situation.

  • endswith() method is used to check if the sentence ends with the target character.
  • modulo(%) operator is used to check if the sentence contains even or odd number of characters
  • escape character is used to print the quotation marks in the else part

Comments are used to explain each line of the code.

#get the user input

sentence = input("Enter a sentence: ")

#check if the sentence ends with ? and has even number of characters

if sentence.endswith("?") and len(sentence) % 2 == 0:

   print("Yes")

#check if the sentence ends with ? and has odd number of characters

elif sentence.endswith("?") and len(sentence) % 2 == 1:

   print("No")

#check if the sentence ends with !

elif sentence.endswith("!"):

   print("Wow")

#used for other situations

else:

   print("You always say \"{}\"".format(sentence))

You may see a similar question at:

https://brainly.com/question/14851610

ACCESS MORE