Skip to content
Snippets Groups Projects
Commit 7a1c758f authored by Ulrich Kerzel's avatar Ulrich Kerzel
Browse files

add examplel for a stand-alone python file

parent 2b82a7c9
Branches
Tags
No related merge requests found
##
## define relevant functions and/or classes
##
# ... your code goes here ...
##
## Main program
## Python uses the name to indicate the main program. If the program is executed, the code below is called.
##
if __name__ == '__main__':
# ... your code goes here ...
##
## define relevant functions
##
def compute_Fibonacci(n_numbers):
return_list = [0, 1]
for i in range(2,n_numbers,1):
Fib = return_list[i-1] + return_list[i-2]
return_list.append(Fib)
return return_list
##
## Main program
## Python uses the name to indicate the main program. If the program is executed, the code below is called.
##
if __name__ == '__main__':
# get 10 Fibonacci numbers
Fib = compute_Fibonacci(n_numbers=10)
# write the Fibonacci numbers to a file
with open('fibonacci.txt','w') as f:
for number in Fib:
f.write(str(number) + '\n')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment