Nov 7, 2015 02:05 PM
(This post was last modified: Nov 7, 2015 02:37 PM by Baba Yaga.)
So I recently saw a thread on hackforums asking how to ask only for a 'y' or 'n' input from the user and how to make it keep asking the person that question until the right input has been reached. Since it was still an open-ended question, I decided to answer it.
The thread I am talking about is here:
http(://)hackforums(.)net/showthread.php?tid=5042581
Credits:
Evolution - help with appending .lower() for more universal input
Hope Aged finds this thread useful 🙂
The thread I am talking about is here:
http(://)hackforums(.)net/showthread.php?tid=5042581
PHP Code
<?php
while True:
play = raw_input("Ready to play? (Y/N): ").lower()
if play != "y" and play != "n":
print ("You have not selected Y or N. Please select a valid option.")
if play == "y":
print ("Let the game's begin")
break #replace break code with thing you want to actually execute
elif play == "n":
print ("Ok you don't want to play")
break
Credits:
Evolution - help with appending .lower() for more universal input
Hope Aged finds this thread useful 🙂


![[Image: AO23sFn.png]](https://i.imgur.com/AO23sFn.png)


![[Image: npafFhp.gif]](https://i.imgur.com/npafFhp.gif)
![[Image: oaVzdr0.png]](https://i.imgur.com/oaVzdr0.png)