0

New to Python and just trying to get a loop to work for my text game.

I used an if/else statement with the while loop at the end but I'm pretty sure I used it wrong. I would prefer hints to figure it out myself instead of the answer, otherwise it's not a learning experience!

rules = input('Would you like to hear the rules? [Yes or No]')
if rules == 'Yes':
    print('Your quest is to explore the Monastery and find the missing armor and sword of the Golden Knight.')
    print('You will have to find a chest plate, gloves, sword, shield, helmet and boots.')
    print('But do be cautious! Kron the Mad lies in wait for you somewhere inside.')
    print('The directions you may travel are North, South, East and West.')
    print('To pick up items, enter get "item name". Your inventory will be displayed upon entering a new area.')
    input('Good luck! Press "Enter" to begin.')
if rules == 'No':
    print('Good luck!')
else:
    while rules != 'Yes' and rules != 'No':
        print('Invalid input')
        input(rules)
  • `if rules == 'No'` This should be `elif`, not `if`. – John Gordon May 19 '23 at 03:06
  • Your while loop is only around the last `input(rules)`, so it only repeats that section. You need to either enclose the entirety of it in a while loop or use the while loop before the `if` statements to ensure you have the correct strings first. Also needing changes is using [elif instead of if - if](https://docs.python.org/3/tutorial/controlflow.html#if-statements) – Shorn May 19 '23 at 03:07
  • `input(rules)` Also this doesn't assign to the `rules` variable, which was probably your intent... – John Gordon May 19 '23 at 03:08
  • Thank you guys, I got it! @JohnGordon, that was my intent and I fixed that by separating the loop from the Yes and No answers. Shorn, this was also very helpful, just a slip up with if/elif/else when trying to figure it out. – Pocho_Oso May 24 '23 at 02:03

0 Answers0