Excerpt from the object-oriented Python conversion
# Weather module for the Weather program
# Created September 2024
# Converted to Python OOP
class Weather:
def __init__(self, fh_array, fl_array, array_lengths, ws, wc):
self._f_high_array = fh_array
self._f_low_array = fl_array
self._ws_mph = ws
self._number_temperatures = array_lengths
self._w_code = wc
self._description = ""
def calculate_average_fahrenheit_high_temp(self):
hi_sum = sum(self._f_high_array)
return hi_sum / self._number_temperatures
def calculate_average_fahrenheit_low_temp(self):
low_sum = sum(self._f_low_array)
return low_sum / self._number_temperatures
def find_weekly_fahrenheit_high_temp(self):
highest_temp = self._f_high_array[0]
for temp in self._f_high_array[1:]:
if temp > highest_temp:
highest_temp = temp
return highest_temp
def find_weekly_fahrenheit_low_temp(self):
lowest_temp = self._f_low_array[0]
for temp in self._f_low_array[1:]:
if temp < lowest_temp:
lowest_temp = temp
return lowest_temp
def determine_description(self):
if self._w_code == 'S':
self._description = "SUNNY"
elif self._w_code == 'P':
self._description = "PARTLY CLOUDY"
elif self._w_code == 'C':
self._description = "CLOUDY"Project objective
Demonstrate formal language concepts, modular design, data handling, program translation, and behavioral equivalence across two programming languages.
What I produced
- Implemented weather calculations in Fortran using a main program and supporting module.
- Compiled and executed the Fortran application.
- Converted the application to Python with classes, methods, and equivalent calculations.
- Compared language structure, types, compilation versus interpretation, modularity, and runtime behavior.
- Validated outputs through multiple manual test cases.
Key decisions
- Keep calculation logic separated from input/output concerns.
- Use Python classes to represent weather data and operations.
- Preserve formulas and test values so equivalence can be evaluated directly.
- Document differences in language syntax and execution model rather than performing a line-for-line translation.
2 languagesFortran and Python
4 test casesBehavior checked across implementations
2 phasesOriginal program and structured conversion
Validation and analysis
- Compiled and ran the Fortran program successfully.
- Ran the Python conversion with the same test inputs.
- Compared expected and actual calculations across four manual cases.