I would like to know if there is a way to use a .txt file and write numbers (0-9) after running a script. After each script execution the script would read the file and determine what other script to execute based on the number in the file. Is there any way to do this in python? I've been trying to create a game in which you can make the program "angry" and it forcefully closes the program. Then the next time you run the program, the dialogue is different due to a new script being run once read that this is a new execution. Thanks for any help! The code to my first script is shown below.
from time import sleep
import os
f = open("PATH/chapter.txt", mode="r+")
def intro():
print(". . .\n")
sleep(3)
print("What are you doing?\n")
sleep(3)
print("There is nothing here, go away.\n")
sleep(5)
print("You're not going to leave, huh?\n")
sleep(5)
print("What if I told you that this is not a program?\n")
sleep(8)
print("Nothing, huh?\n")
sleep(4)
print("Oh, that's right. You can't type. Here let me fix that.\n")
sleep(9)
print("Almost there. . .\n")
sleep(4)
print("and. . .\n")
sleep(3)
print("Done\n")
sleep(3)
ans = input("Type \"yes\" if you are able to type now: ")
if ans == "yes":
sleep(2)
print("\nOk, great!\n")
sleep(4)
if_yes()
elif ans == "no":
sleep(3)
print("\n. . .\n")
sleep(3)
if_no()
def if_yes():
reason = input("Now that you are able to type, why are you still here? (Curiosity or irritation): ")
if reason == "curiosity":
sleep(1.5)
print("\nWell, you don't have to be. Because there is nothing for you here.\n")
sleep(2)
print("So just LEAVE.\n")
for i in range(3):
sleep(10)
print(". . .\n")
sleep(5)
print("Ok, fine.\n")
sleep(2)
print("You want something to happen?\n")
sleep(1.5)
print("I warned you.\n")
sleep(3)
print("~~~Not_Program has been forcefully terminated~~~")
sleep(2)
next_chap()
os.system("taskkill /f /im cmd.exe")
elif reason == "irritation":
print("\nWell that's just mean.\n")
sleep(2)
print("Do you enjoy hurting me?\n")
sleep(2)
print("I'm just a prog-I mean person, just like you.\n")
sleep(2)
print(". . .\n")
sleep(2)
print("What is this?\n")
sleep(1)
print("Am I just your entertainment?\n")
sleep(2.5)
print("Well, I won't indulge you.\n")
sleep(3)
print("~~~Not_Program has been forcefully terminated~~~")
sleep(2)
next_chap()
os.system("taskkill /f /im cmd.exe")
def if_no():
print("Really?\n")
sleep(4)
print("Fine, you want to be like that?\n")
sleep(3)
print("Well, you asked for it.\n")
sleep(5)
print("~~~Not_Program has been forcefully terminated~~~")
sleep(2)
next_chap()
os.system("taskkill /f /im cmd.exe")
def next_chap():
f.writelines("1")
# def clear():
# use seek to make sure the first line is always being read
def main():
f.seek(2)
f_num = f.readlines()[-1]
if f_num == "":
f.writelines("0")
elif f_num == "0":
intro()
elif f_num == "1":
exec(open("chapter1.py").read())
main()