Nov-12-2019, 11:03 AM
I'm currently doing a tutorial on while loops, I followed along fine, but I always try to add something of my own to each code he teaches, so my brain has to think rather than just copy, but I'm stuck on something I want to add...
I realize it's probably quite basic for you guys but it's difficult for me psychologically to move on until I have done it (weirdo), I tried several different ideas and "wasted" a good couple hours on it (at least I've learnt what wont work), but it's possible that it just requires something I haven't learnt yet.
It's my first post, so I'm hoping you guys suffer noobs gladly.
secret_number = 9 guess_count = 0 guess_limit = 3 while guess_count < guess_limit: guess = int(input("Guess: ")) guess_count += 1 if guess == secret_number: print("You win!") break else: print("Fail!")This is as per the tutorial. As you can see it works fine for numbers input, but at the moment if someone adds a non-numerical character it just responds with an error. I wanted to add something that would give a reply along the lines of "Invalid answer, numbers only please." then revert back to the first guess in the loop.
I realize it's probably quite basic for you guys but it's difficult for me psychologically to move on until I have done it (weirdo), I tried several different ideas and "wasted" a good couple hours on it (at least I've learnt what wont work), but it's possible that it just requires something I haven't learnt yet.
It's my first post, so I'm hoping you guys suffer noobs gladly.
