+ 2

How do I make this work?

I need a program that the user can put in a statement or a question, and if the sentence has a ? then it outputs a random yes or no. I can’t figure out how to make it only look for the question mark. Can anyone help?

29th Sep 2019, 10:25 PM
Jesse Bradley
Jesse Bradley - avatar
1 Resposta
+ 1
To get the character "?", you can try calling the variable of your input as var [-1], where -1 takes the last character of your string, in this case the "?". If you are programming in Python for example, you can use the random library with randint() function to have the code randomly choose its two options like this: from random import * var = input("what is your question: ") if var[-1] == "?": x = randint(1,2) if x == 1: print("yes") elif x == 2: print("no")
30th Sep 2019, 3:03 AM
Wardy Spirit
Wardy Spirit - avatar