This used to work. I must have accidentally altered a character or something.
Note: The odd part is that I can drag and drop various parts of it into the interpreter and they run fine. I can get it to output it to a file just fine by dragging the function over. It crashes where commented when I attempt to run the entire thing.
PHP Code:
#! /usr/bin/python
def get_run():
r = raw_input('\n\nRun again? (y/n): ')
while r != 'y' and r != 'Y' and r != 'n' and r != 'N':
r = raw_input('Run again? (y/n): ')
if r == 'Y':
r = 'y'
return r
def get_dest():
d = ''
while d != 's' and d != 'S' and d != 'f' and d != 'F':
d = raw_input('Output to (F)ile or (S)creen?: ')
if d == 'S': d = 's'
if d == 'F': d = 'f'
return d
def fib_calc(d):
n = long(raw_input('\nPlease enter a number: '))
if n >= 0:
a, b, output = 0, 1, [0]
while b <= n:
output.append(b)
a, b = b, a + b
if d == 's':
print '\nFibanacci numbers <=', n, '\n',
print output,
elif d == 'f':
fname = 'Desktop/FibOutput' + str(n)
print fname
check = raw_input('one')
#crash here --->
f = open(fname, 'w')
check = raw_input('two')
f.write(str(output))
f.close
print '\nResults written to ', fname,
else: print '\nError: Unsupported number.',
run = 'y'
while run == 'y':
dest = get_dest()
fib_calc(dest)
run = get_run()
Thanks for any thoughts.
Bookmarks