PAU-Selectividad, pregunta formulada por KHALILKAK, hace 3 meses

4. Write a program that reads a one-line sentence as input and then displays the following answer: 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 entry 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, always display the words you say followed by the input string enclosed in quotation marks. Your output must be on one line. Be sure to note that in the latter case, your output must include quotes around the echoing input string. In all other cases, there are no quotes in the output. Your program doesn't have to check the input to see that the user has entered a legitimate sentence.​

Respuestas a la pregunta

Contestado por CloverInSpanish
0
  • See the code below, written in Python 3.X

sentence = input()

if sentence.endswith('?'):

 if len(sentence) % 2 == 0:

   print("Yes")

 else:

   print("No")

elif sentence.endswith('!'):

 print("Wow")

else:

 print(f'The words you say: "{sentence}"')

Adjuntos:

KHALILKAK: hi
CloverInSpanish: Hi
KHALILKAK: تتكلمي عربي
KHALILKAK: hi
CloverInSpanish: I don't speak arabic!
KHALILKAK: If you can speak Arabic, we can understand each other more
KHALILKAK: Well you don't have to
KHALILKAK: The solution is right or wrong
CloverInSpanish: The answer is correct
KHALILKAK: Thank you we are honored
Otras preguntas