[Tutor] Solved Int to String/Problem about Overwriting
Albert Antiquera
gundamone@hotmail.com
Sun, 20 Aug 2000 17:19:45 EDT
This is a multi-part message in MIME format.
------=_NextPart_000_1fac_49a2$72f
Content-Type: text/plain; format=flowed
Hi guys!
Thanks for the help on that Integer to String conversion(I knew what str()
was but I just forgot all about it;))Anyway, I got the program to work but I
got one more problem: When I say 'n' to the 'save file?' part, it erases
whatever was saved on that file before. I know it has something to do with
the 'open("slope.txt","wb")' part but when I change "wb" to "rb" I get an
error. Here's the code if anybody wants to inspect it (I also put it as an
attachment if you got trouble reading it here):
#!E:/Python/Python.exe
#Author: Albert Antiquera
#Program: Find the slope and Y-intercept (coming)
#IMPORTANT!!!: There is a bug here that I haven't figured out yet: Whwn you
say 'N' to the
# 'save file?' question, it erases whatever was on the file
when you last saved
# it. I know it got something to do with that first 'open'
command.
import sys
def slope():
x1 = input("Enter a value for X1: ")
x2 = input("Enter a value for X2: ")
y1 = input("Enter a value for Y1: ")
y2 = input("Enter a value for Y2: ")
slp = (y2-y1)/(x2-x1)
conv = str(slp)
print "The slope is:", conv
outp = open("slope.txt", "wb") #I HAVE TO FIGURE THIS ONE OUT SO IT
WON'T OVERWRITE"
val = "-----BEGIN OUTPUT FILE---------------\n"
val2 ="The Slope is:%s\n" %(conv,)
val3 ="------END OUTPUT FILE----------------"
inp = [val,val2,val3]
choice = raw_input("Do you want to save the result to a file?(Y or N):")
if choice == 'y':
outp.writelines(inp)
print "1 file was saved!!"
else:
print "No File was Saved!!"
sys.exit(0)
print"------------------SLOPE PROGRAM--------------------------"
slope()
print"---------------END OF SLOPE PROGRAM----------------------"
Thanks!!!!
Albert
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
------=_NextPart_000_1fac_49a2$72f
Content-Type: text/plain; name="slope.py"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="slope.py"
#!E:/Python/Python.exe
#Author: Albert Antiquera
#Program: Find the slope and Y-intercept (coming)
#IMPORTANT!!!: There is a bug here that I haven't figured out yet: Whwn you
say 'N' to the
# 'save file?' question, it erases whatever was on the file
when you last saved
# it. I know it got something to do with that first 'open'
command.
import sys
def slope():
x1 = input("Enter a value for X1: ")
x2 = input("Enter a value for X2: ")
y1 = input("Enter a value for Y1: ")
y2 = input("Enter a value for Y2: ")
slp = (y2-y1)/(x2-x1)
conv = str(slp)
print "The slope is:", conv
outp = open("slope.txt", "wb") #I HAVE TO FIGURE THIS ONE OUT SO IT
WON'T OVERWRITE"
val = "-----BEGIN OUTPUT FILE---------------\n"
val2 ="The Slope is:%s\n" %(conv,)
val3 ="------END OUTPUT FILE----------------"
inp = [val,val2,val3]
choice = raw_input("Do you want to save the result to a file?(Y or N):")
if choice == 'y':
outp.writelines(inp)
print "1 file was saved!!"
else:
print "No File was Saved!!"
sys.exit(0)
print"------------------SLOPE PROGRAM--------------------------"
slope()
print"---------------END OF SLOPE PROGRAM----------------------"
------=_NextPart_000_1fac_49a2$72f--