<div dir="ltr">I have a script that outputs results to a file (one file, reused.) I would like to have an output file in this format<div><br></div><div>#--------------------</div><div>(blank line)</div><div>(output from program (only one line))</div>
<div>name</div><div>(T/F)</div><div>(result iteration, shortened to x.)</div><div>#---------------------</div><div>so like this</div><div>#---------------------</div><div><br></div><div>55</div><div>Joe</div><div>false</div>
<div>1</div><div><br></div><div>96</div><div>Bob</div><div>true</div><div>2</div><div><br></div><div>28</div><div>Mike</div><div>true</div><div>3</div><div>#---------------------</div><div><br></div><div>I couldn't think of a way to read the last written number (it would be a multiple of 5). I know how to add 1 and print. Also, how would I arrange </div>
<div>#--------</div><div><div>output.write("\n")</div><div>output.write(x_string)</div><div>output.write("\n")</div><div>output.write(name)</div><div>output.write("\n")</div><div>output.write(exists_string)</div>
<div>output.write("\n")</div></div><div>#-------</div><div>so that it didn't show up like this</div><div>FIRST TIME</div><div><div><br></div><div>101</div><div>nope</div><div>True</div><div>1</div></div><div>
SECOND TIME</div><div><div><br></div><div>101</div><div>nope</div><div>True</div><div>1</div><div>4554073</div><div>yup</div><div>True</div></div><div><br></div><div><br></div><div><br></div><div>Also, how would I make this program better in general?</div>
<div><br></div><div><br></div><div><br></div><div><div>#BEGIN</div><div># Importing exists. Simple English. Nonsensical, but English nonetheless.</div><div>from os.path import exists</div><div>#Asking for your name</div><div>
name = raw_input("Hello!\nWhat is your name?\n\n")</div><div>#Asking for the number and reacting to given response</div><div>x = int(raw_input("\tFor the purposes of testing, please select a number between one and 100\n\n\t"))</div>
<div><br></div><div>if x < 0:</div><div><span class="" style="white-space:pre"> </span>x = 4554073</div><div><span class="" style="white-space:pre"> </span>print "\t\tNo negatives, asshole. Number changed to '4554073' for 'ASSHOLE', asshole."</div>
<div>elif x == 0:</div><div><span class="" style="white-space:pre"> </span>print "\t\tMore than zero."</div><div>elif x > 100:</div><div><span class="" style="white-space:pre"> </span>x = 101</div><div><span class="" style="white-space:pre"> </span>print "\t\tDon't fuck with the computer."</div>
<div>elif x == 42:</div><div><span class="" style="white-space:pre"> </span>print "\t\tThe meaning of life, the universe and everything."</div><div>elif x == 7:</div><div><span class="" style="white-space:pre"> </span>print "\t\t7. How... creative. *cough* UNORIGINAL *cough*"</div>
<div>elif x == 3:</div><div><span class="" style="white-space:pre"> </span>print "\t\t3! It's a magic numba\'. Yes it is! It's a magic numba\'."</div><div>elif x == 37:</div><div><span class="" style="white-space:pre"> </span>print "\t\tThe two most common numbers."</div>
<div>elif x == 99:</div><div><span class="" style="white-space:pre"> </span>print "\t\tI got 99 problems and a- wait, no, that's your IQ."</div><div>elif x == 27:</div><div><span class="" style="white-space:pre"> </span>print "\t\tCONGRATULATATIONS! YOU'VE FOUND MY FOAVORITE NOMBER!"</div>
<div>else:</div><div><span class="" style="white-space:pre"> </span>print "In all aspects your number appears to be normal."</div><div>#Changing name to a string</div><div>name_string = "%s" % name</div>
<div>#Changing x to a string</div><div>x_string = "%s" % x</div><div>#Checking if file exists for archival purposes</div><div>exists = exists("number_output.txt")</div><div>exists_string = "%s" % exists</div>
<div>#Opening output file</div><div>number_output = 'number_output.txt'</div><div>output = open(number_output, 'a')</div><div>#Writing to file</div><div>output.write("\n")</div><div>output.write(x_string)</div>
<div>output.write("\n")</div><div>output.write(name)</div><div>output.write("\n")</div><div>output.write(exists_string)</div><div>output.write("\n")</div><div>#END</div></div></div>