-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample6.py
More file actions
22 lines (16 loc) · 720 Bytes
/
example6.py
File metadata and controls
22 lines (16 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import argparse
import datetime
parser = argparse.ArgumentParser(description='Returns a string containing the name and age of the person')
parser.add_argument('-f', '--first', help='first name', type=str, required=False, dest='first_name')
parser.add_argument('-l', '--last', help='last name', type=str, required=True, dest='last_name')
parser.add_argument('--yob', help='year of birth', type=int, required=False, dest='birth_year')
args = parser.parse_args()
if args.first_name:
names = [args.first_name]
else:
names = []
names.append(args.last_name)
full_name = ' '.join(names)
current_year = datetime.datetime.utcnow().year
age = current_year - args.birth_year
print(f'{full_name} is {age} years old.')