-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path04 greeting call stack.py
86 lines (78 loc) · 5.52 KB
/
04 greeting call stack.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Вывод приветствия.
# Здесь мы создаем две функции, которые вызываются из третьей функции.
# Здесь мы можем рассмотреть работу стека вызовов.
# ----------
# Printing greetings.
# Here we create two functions, that are called by the third function.
# Here we can see how a call stack works.
# Создаем функцию "how_are_you", которая выводит на экран текст "How are you, username ?" при помощи функции "print()".
# Эта функция принимает один входной параметр: имя "username" того, кого приветствуют.
# ----------
# Create the function "how_are_you" that prints the message "How are you, username ?" to the screen
# using the function "print()".
# This function accepts one parameter: the name "username" of the person being greeted.
def how_are_you(username):
print("How are you,", username, "?")
# Создаем функцию "bye", которая выводит на экран текст "Ok, bye!" при помощи функции "print()".
# Эта функция не принимает никаких входных параметров.
# ----------
# Create the function "bye" that prints the message "Ok, bye!" to the screen using the function "print()".
# This function doesn't have any parameters.
def bye():
print("Ok, bye!")
# Создаем функцию "greet", которая выводит на экран текст "Hello, username !" при помощи функции "print()",
# а также вызывает функции "how_are_you" и "bye".
# Эта функция принимает один входной параметр: имя "username" того, кого приветствуют.
# ----------
# Create the function "greet" that prints the message "Hello, username !" to the screen using the function "print()"
# and calls the functions "how_are_you" and "bye".
# This function accepts one parameter: the name "username" of the person being greeted.
def greet(username):
# Стек вызовов содержит функцию "greet".
# Функция "greet" выполняет свою работу: выводит на экран
# сообщение "Hello, username !" при помощи функции "print()".
# ----------
# The call stack contains the function "greet".
# The function "greet" does its work: it prints
# the message "Hello, username !" to the screen using the function "print()".
print("Hello,", username, "!")
# Функция "greet" вызывает функцию "how_are_you".
# В стеке вызовов работа функции "greet" приостанавливается.
# В стек вызовов наверх добавляется функция "how_are_you".
# Функция "how_are_you" выполняет свою работу: выводит на экран сообщение "How are you, username ?"
# ----------
# The function "greet" calls the function "how_are_you".
# The function "greet" is suspended in the call stack.
# The function "how_are_you" is added to the call stack.
# The function "how_are_you" does its work: it prints the message "How are you, username ?" to the screen.
how_are_you(username)
# Функция "how_are_you" завершает свою работу, передает управление функции "greet" и убирается из стека вызовов.
# Функция "greet" возобновляет свою работу и выводит на экран
# текст "Ok, bye in 3 .. 2 .. 1" при помощи функции "print()".
# ----------
# The function "how_are_you" stops its work, transfers control to the function "greet"
# and is removed from the call stack.
# The function "greet" resumes its work and prints
# the message "Ok, bye in 3 .. 2 .. 1" to the screen using the function "print()".
print("Ok, bye in 3 .. 2 .. 1")
# Функция "greet" вызывает функцию "bye".
# В стеке вызовов работа функции "greet" снова приостанавливается.
# В стек вызовов наверх добавляется функция "bye".
# Функция "bye" выполняет свою работу: выводит на экран сообщение "Ok, bye!"
# ----------
# The function "greet" calls the function "bye".
# The function "greet" is suspended again in the call stack.
# The function "bye" is added to the call stack.
# The function "bye" does its work: it prints the message "Ok, bye!" to the screen.
bye()
# Функция "bye" завершает свою работу, передает управление функции "greet" и убирается из стека вызовов.
# Функция "greet" возобновляет свою работу.
# Функция "greet" завершает свою работу убирается из стека вызовов.
# ----------
# The function "bye" stops its work, transfers control to the function "greet" and is removed from the call stack.
# The function "greet" resumes its work.
# The function "greet" stops its work and is removed from the call stack.
# Пытаемся поприветствовать пользователя John Shepard.
# ----------
# Try to greet user John Shepard.
greet("John Shepard")