forked from wadehuber/codeexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvancedfunctions.py
More file actions
36 lines (27 loc) · 925 Bytes
/
Copy pathadvancedfunctions.py
File metadata and controls
36 lines (27 loc) · 925 Bytes
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
"""
advancedfunctions.py
This file contains simple functions that demonstrate the use of positional
and keyword arguments, as well as variable-length argument lists.
"""
def greet(name, /, greeting="Hello"):
"""Greet a person with a message.
Args:
name (str): The name of the person.
greeting (str, optional): The greeting message. Defaults to "Hello".
Returns:
str: The formatted greeting message.
"""
return f"{greeting}, {name}!"
def stats(*nums):
"""Calculate basic statistics for a set of numbers.
Returns:
tuple: A tuple containing the minimum, maximum, and average of the numbers.
"""
if not nums:
return None, None, None
return min(nums), max(nums), sum(nums) / len(nums)
print(greet("Leia"))
print(greet("Luke", "Use the Force"))
print(greet("Han", "Never tell me the odds"))
print(stats(7))
print(stats(10, 20, 30, 40))