example programs tests
This commit is contained in:
20
examples/fibonacci.simple
Normal file
20
examples/fibonacci.simple
Normal file
@ -0,0 +1,20 @@
|
||||
def fibonacci_rec(n):
|
||||
if n <= 1:
|
||||
n
|
||||
else:
|
||||
fibonacci_rec(n - 1) + fibonacci_rec(n - 2)
|
||||
|
||||
|
||||
def fibonacci_it(n):
|
||||
if n <= 1:
|
||||
n
|
||||
else:
|
||||
fib = 1
|
||||
prev = 1
|
||||
i = 2
|
||||
while i < n:
|
||||
temp = fib
|
||||
fib = fib + prev
|
||||
prev = temp
|
||||
i++
|
||||
fib
|
13
examples/inheritance.simple
Normal file
13
examples/inheritance.simple
Normal file
@ -0,0 +1,13 @@
|
||||
object shape:
|
||||
size = 1
|
||||
|
||||
def area:
|
||||
size
|
||||
|
||||
object square(parent=shape):
|
||||
def area:
|
||||
size * size
|
||||
|
||||
object circle(parent=shape):
|
||||
def area:
|
||||
3.1415 * size * size
|
Reference in New Issue
Block a user