-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyield.py
More file actions
41 lines (38 loc) · 1.03 KB
/
yield.py
File metadata and controls
41 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# In The Name of God
# =======================================
# [] File Name : yield.py
#
# [] Creation Date : 14-01-2020
#
# [] Created By : Parham Alvani <parham.alvani@gmail.com>
# =======================================
def fibonacci():
print('initiation')
n = 0
a, b = 0, 1
while True:
print(f'{n}')
yield b
a, b = b, a + b
n += 1
fibo = fibonacci()
print(f'n: 0')
next(fibo)
print(f'n: 1')
next(fibo)
def psychologist():
print('Please tell me your problem')
while True:
answer = (yield)
if answer is not None:
if answer.endswith('?'):
print("Don't ask yourself too much questions")
elif 'good' in answer:
print("Ahh that's good, go on")
elif 'bad' in answer:
print("Don't be so negative")
free = psychologist()
next(free) # can't send non-None value to a just-started generator
free.send('I feel bad')
free.send("Why I shouldn't?")
free.send("ok then I should find what is good for me")