I’m back with another return question, and actual code!
I was working on this ‘create and edit an external file’ problem. As I typed “add another?” subroutine “def done()”, the AI popped in an "if yes, return true/if no return false’ and I realized I’ve never actually USED return true/return false. I’ve only just read about it. So I incorporated it and am doing something wrong.
My code is a subroutine, “def done()”, and a while True loop.
In the subroutine, a Y returns True and an N returns False. So, I stuck an exit() command after, and NOT indented with, the while True loop. I thought that a returned False would end the while True loop and execute the exit() command.
I was mistaken. The returned False acts just like a returned True.
If I indent the exit(), as soon as the done() subroutine finishes, it exits. No surprise there.
I have completed the lesson without the return True/return False, so my question isn’t holding up my lesson.
I’m posting the code (without comments) and my question is:
Did I format the code wrong or do I have a basic misunderstanding of the return True/False function and how it works?
Maybe both?
Thanks!
Drats
title="🌟🌟🌟HIGH SCORE TABLE🌟🌟🌟"
print(f"{title:^50}")
def done():
fini=input("Add another?(Y/N)\n").title()
if fini=="Y":
return True
elif fini=="N":
return False
else:
print("Invalid Input, please try again.")
done()
while True:
f = open("scoreHIGH.txt", "a+")
initials = input("Type your initials here: ")
f.write(f"Initials: {initials}\n")
score = input("Type your score here: ")
f.write(f"Score: {score}\n\n")
done()
exit()