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

for and while loops

parent b4c47084
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
##
## print the word 'run' from the string 'nurse'
##
my_word = 'nurse'
print(my_word[2::-1])
```
%% Output
run
%% Cell type:code id: tags:
``` python
##
## Fibonacci Numbers --- For Loop
##
Fibonacci = [0, 1]
for i in range(2,10,1):
Fib = Fibonacci[i-1] + Fibonacci[i-2]
Fibonacci.append(Fib)
print('The Fibonacci numbers are: {}'.format(Fibonacci))
```
%% Output
The Fibonacci numbers are: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
%% Cell type:code id: tags:
``` python
##
## Fibonacci Numbers --- While Loop
##
Fibonacci = [0, 1]
while len(Fibonacci) < 10:
Fib = Fibonacci[-1] + Fibonacci[-2]
Fibonacci.append(Fib)
print('The Fibonacci numbers are: {}'.format(Fibonacci))
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment