-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry_again
More file actions
192 lines (152 loc) · 5.82 KB
/
try_again
File metadata and controls
192 lines (152 loc) · 5.82 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
"""
File: utils_case.py
Purpose: Reusable header/tagline module for analytics projects.
Description:
A short, first-week module to demonstrate key skills:
- declare basic variables (bool, int, str, list)
- compose a reusable f-string (a formatted-string header block)
- expose a function named get_tagline() that can be imported into other modules
- run this file as a script via main() using the if __name__ == '__main__' pattern
Author: Kim Hummel
"""
#####################################
# Import Modules
#####################################
# For a summary list of key modules that come pre-packaged with Python,
# see the notes in the requirements.txt file (included in all projects).
# Import modules from the Python Standard library
import statistics
# Additional external packages must be listed in requirements.txt or pyproject.toml
# and installed in the active .venv
# Import external packages
import loguru # Easy logging
import pyttsx3 # type: ignore # Text-to-speech engine
#####################################
# Configure Simple Logger (better than print statements)
#####################################
logger = loguru.logger
logger.add(
"project.log",
level="INFO",
rotation="100 KB",
backtrace=False,
diagnose=False,
format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {name}:{line} | {message}",
)
logger.info("Logger loaded.")
#####################################
# Declare Global Variables
#####################################
# ----------------------------------
# Define Boolean variables (True/False)
# ----------------------------------
is_accepting_clients: bool = True
offers_remote_workshops: bool = True
is_hiring: bool = False
# ----------------------------------
# Define Integer variables
# ----------------------------------
current_year: int = 2025
year_started: int = 2019
number_of_employees: int = 12
# ----------------------------------
# Define String variables
# ----------------------------------
author: str = "Kim Hummel"
organization: str = "Hummel Analytics"
motto: str = "Only the best for the best"
# ----------------------------------
# Define List variables
# ----------------------------------
# example list of strings
services: list[str] = ["Data Analysis", "Machine Learning", "Business Intelligence"]
office_locations: list[str] = ["Philadelphia", "Cherry Hill", "Tuscaloosa", "Mobile"]
current_city: [str] = "Philadelphia, PA"
# example list of floating point numbers
satisfaction_scores: list[float] = [4.8, 4.6, 4.9, 5.0, 4.7]
years_in_service: list[float] = [9.5, 16.2, 5.4, 3.3]
# ----------------------------------
# Use built-in Python operators (such as - + * /)
# and built-in Python functions (such as min, max, len, upper, lower, etc.)
# ----------------------------------
years_active: int = current_year - year_started
min_score: float = min(satisfaction_scores)
max_score: float = max(satisfaction_scores)
count_of_services: int = len(services)
count_of_scores: int = len(satisfaction_scores)
count_of_locations: int = len(office_locations)
min_score_loc: float = min(years_in_service)
max_score_loc: float = max(years_in_service)
# ----------------------------------
# Use the built-in statistics module functions (such as mean, stdev, etc.)
# ----------------------------------
mean_score: float = statistics.mean(years_in_service)
stdev_score: float = statistics.stdev(years_in_service)
# ----------------------------------
# Compose a reusable formatted string (f-string) using triple quotes
# ----------------------------------
byline: str = f"""
**********************************************************
{organization} — Project Header
**********************************************************
Author: {author}
Motto: {motto}
Years Active: {years_active}
Accepting New Clients?: {is_accepting_clients}
Remote Workshops?: {offers_remote_workshops}
Services: {services}
Client Satisfaction Scores: {satisfaction_scores}
Minimum Satisfaction Score: {min_score}
Maximum Satisfaction Score: {max_score}
Mean Satisfaction Score: {mean_score:.2f}
Standard Deviation: {stdev_score:.2f}
Current City: {current_city}
Number of Locations: {count_of_locations}
Min. Years at a Location: {min_score_loc}
Max. Years at a Location: {max_score_loc}
**********************************************************
"""
#####################################
# Define Global Functions
#####################################
def get_byline() -> str:
"""
Return the reusable byline/tagline string.
"""
return byline
def read_byline_aloud() -> None:
"""
Use text-to-speech to read the byline aloud.
"""
engine = pyttsx3.init()
if engine is not None:
engine.say(str(get_byline()))
engine.runAndWait()
#####################################
# Define Function main() function for this module.
#####################################
def main() -> None:
"""
Use this main() function to test this module when
running it as a script.
"""
loguru.logger.info("STARTING main()..")
loguru.logger.info("Byline:\n" + get_byline())
try:
# TODO: Uncomment next line if you want audio feedback (use CTRL+C to stop)
# read_byline_aloud()
pass
except KeyboardInterrupt:
logger.info("Speech interrupted by user (Ctrl+C).")
except Exception as ex:
logger.warning(f"Text-to-speech skipped: {ex}")
loguru.logger.info("This module is organized like all Python modules.")
loguru.logger.info("We write professional Python from the start.")
loguru.logger.info("END main()...")
#####################################
# Conditional Execution
#####################################
# If we are running this file as a script then call main()
# and verify our code works as expected.
if __name__ == "__main__":
main()