Python is indentation-sensitive, so from the line
x = str(...
this part does not belong to the while loop.
Try
import sys
while True:
answer = input('Do you want to continue?:')
if answer.lower().startswith("y"):
print("ok, carry on then")
elif answer.lower().startswith("n"):
sys.exit()
x = str(input("Enter A or B for a Trick Or a Treat!: "))
if x == 'a':
print("treat")
else:
print("trick")
Python Indentation[
^]