-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.py
More file actions
56 lines (45 loc) · 1.41 KB
/
switch.py
File metadata and controls
56 lines (45 loc) · 1.41 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
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/local/bin/python3
""" A program designed to display switching in Python """
import sys
import courses
def print_text(text, *args, **kwargs):
"""Print just the text value"""
print('text: ' + text)
def print_args(text, *args, **kwargs):
"""Print just the argument list"""
print('args:')
for i, arg in enumerate(args):
print('{0}: {1}'.format(i, arg))
def print_kwargs(text, *args, **kwargs):
"""Print just the keyword arguments"""
print('keyword args:')
for k, v in kwargs.items():
print('{0}: {1}'.format(k, v))
def print_all(text, *args, **kwargs):
"""Prints everything"""
print_text(text, *args, **kwargs)
print_args(text, *args, **kwargs)
print_kwargs(text, *args, **kwargs)
def quit(text, *args, **kwargs):
"""Terminates the program."""
print("Quitting the program")
sys.exit()
if __name__ == "__main__":
switch = {
'text': print_text,
'args': print_args,
'kwargs': print_kwargs,
'all': print_all,
'course': courses.description,
'quit': quit
}
options = switch.keys()
prompt = 'Pick an option from the list ({0}): '.format(', '.join(options))
while True:
inp = input(prompt)
option = switch.get(inp, None)
if option:
option('Python','is','fun',course="Python 101",publisher="O'Reilly")
print('-' * 40)
else:
print('Please select a valid option!')