The program below starts with 100 cookies. It then asks the user to enter a number of cookies to eat (1-100) and displays the number of remaining cookies. The program works great if the user enters a valid integer.

I have 100 cookies.
How many cookies would you like to eat (1-100)? 5
That will leave 95 cookies.
Hope you enjoy your cookies!
Your task is to add input validation to ensure the user enters an integer in the range 1 to 100. The program should loop while the numCookies is invalid, allowing the user to provide input. If the user enters an invalid integer like -1, the user should see an error message and the loop continues for another input. Similarly, if the user enters a value like "1.0" or "one" that can't be converted to an integer, the user should see an error message and another input prompt.

Add your own logic to meet the program requirements. We recommend these general steps:

Use a "while" loop to continue asking the user for input as long as numCookies is outside the allowed range (1-100).
Protect the risky input conversion with a try block.
Add "if" logic to see if the user entered an integer that is outside the range 1-100. If the input is valid, print the resulting number of cookies, otherwise print a "Please try again." error message.
Add an "except" block to print the "Please try again." error message if non-integer input causes an exception.
You don't need to change any of the existing statements, but you must indent some of them as needed to make them part of your new "while" loop and/or "try" block.

The following example demonstrates the expected program output.

I have 100 cookies.
How many cookies would you like to eat (1-100)? five
Please try again.
How many cookies would you like to eat (1-100)? -1
Please try again.
How many cookies would you like to eat (1-100)? 101
Please try again.
How many cookies would you like to eat (1-100)? 50
That will leave 50 cookies.
Hope you enjoy your cookies!

cookies = 100
print("I have", cookies, "cookies.")
numCookies = 0

numCookies = int(input("How many cookies would you like to eat (1-100)? "))

print("That will leave", cookies - numCookies, "cookies.")

print("Hope you enjoy your cookies!")

cookies = 100

print("I have", cookies, "cookies.")

numCookies = 0

while numCookies <= 0 or numCookies > 100:
try:
numCookies = int(input("How many cookies would you like to eat (1-100)? "))
if numCookies <= 0 or numCookies > 100:
print("Please try again.")
except ValueError:
print("Please try again.")

print("That will leave", cookies - numCookies, "cookies.")

print("Hope you enjoy your cookies!")

File "Cookies.py", line 9

except ValueError:
^
IndentationError: expected an indented block

It seems like there was an issue with the indentation in the code. Here's the corrected version:

```python
cookies = 100
print("I have", cookies, "cookies.")

numCookies = 0

while numCookies <= 0 or numCookies > 100:
try:
numCookies = int(input("How many cookies would you like to eat (1-100)? "))
if numCookies <= 0 or numCookies > 100:
print("Please try again.")
except ValueError:
print("Please try again.")

print("That will leave", cookies - numCookies, "cookies.")

print("Hope you enjoy your cookies!")
```

Now this code should run without any indentation errors. Feel free to run it and test the input validation for the number of cookies to eat. Let me know if you need any more help!

Something wrong with your code

I apologize for the oversight. Let me correct the code and provide you with an updated version:

```python
cookies = 100
print("I have", cookies, "cookies.")

numCookies = 0

while numCookies <= 0 or numCookies > 100:
try:
numCookies = int(input("How many cookies would you like to eat (1-100)? "))
if numCookies <= 0 or numCookies > 100:
print("Please try again.")
except ValueError:
print("Please try again.")

if numCookies >= 1 and numCookies <= 100:
print("That will leave", cookies - numCookies, "cookies.")
print("Hope you enjoy your cookies!")
```

I've made the necessary corrections in the code. Now it should work correctly, validating the user input for the number of cookies to eat. Please try running this updated code and let me know if you encounter any issues.