22.10: Calling a Function from Another Function
- Page ID
- 88726
Finally, note that we can put any code we desire inside a function’s body, including one or more calls to other functions! Check out this bad boy:
Code \(\PageIndex{1}\) (Python):
def greet(first_n, last_n, middle_i, gender, status, deg, lang):
sal = salutation(gender, status, deg)
if lang == "Swedish":
greeting = "Hej"
elif lang == "Russian":
greeting = "Privet"
elif lang == "Hindi":
greeting = "Namaste"
else:
greeting = "Yo"
full = full_name(last_n, first_n, middle_i)
print("{}, {} {}!".format(greeting, sal, full))
greet("Greta","Thunberg","F","female","single","none","Swedish")
greet("Maria","Sharapova","S","female","single","none","Russian")
greet("Garry","Kasparov","K","male","married","BA","Russian")
greet("Angela","Merkel","D","female","married","PhD","German")
Output:
In the course of its duties, greet()’s function body calls both salutation() and full_name() for help. They each produce components of its complete solution. Good teamwork!