|
|
""" |
|
|
Example usage of Height Conversion Tool |
|
|
""" |
|
|
|
|
|
from height_converter import HeightConverter |
|
|
|
|
|
|
|
|
def main(): |
|
|
"""Demonstrate various uses of the HeightConverter.""" |
|
|
|
|
|
|
|
|
converter = HeightConverter() |
|
|
|
|
|
print("=" * 60) |
|
|
print("Height Conversion Tool - Examples") |
|
|
print("=" * 60) |
|
|
|
|
|
|
|
|
print("\n1. Convert 5'10\" to centimeters:") |
|
|
height_cm = converter.feet_to_cm(5, 10) |
|
|
print(f" Result: {height_cm} cm") |
|
|
|
|
|
|
|
|
print("\n2. Convert 180 cm to feet/inches:") |
|
|
feet, inches = converter.cm_to_feet(180) |
|
|
print(f" Result: {feet}'{inches}\"") |
|
|
|
|
|
|
|
|
print("\n3. Convert 1.75 meters to feet/inches:") |
|
|
feet, inches = converter.meters_to_feet(1.75) |
|
|
print(f" Result: {feet}'{inches}\"") |
|
|
|
|
|
|
|
|
print("\n4. Convert 6 feet to meters:") |
|
|
meters = converter.feet_to_meters(6, 0) |
|
|
print(f" Result: {meters} m") |
|
|
|
|
|
|
|
|
print("\n5. Convert using string input:") |
|
|
heights = ["5'10\"", "180cm", "1.75m"] |
|
|
for height in heights: |
|
|
result_cm = converter.convert(height, "cm") |
|
|
result_feet = converter.convert(height, "feet") |
|
|
print(f" {height:10} = {result_cm:12} = {result_feet}") |
|
|
|
|
|
|
|
|
print("\n6. Batch conversion (cm to feet/inches):") |
|
|
heights_cm = [150, 160, 170, 180, 190] |
|
|
print(f" {'CM':<6} {'Feet/Inches':<12}") |
|
|
print(f" {'-'*6} {'-'*12}") |
|
|
for height in heights_cm: |
|
|
feet, inches = converter.cm_to_feet(height) |
|
|
print(f" {height:<6} {feet}'{inches:.1f}\"") |
|
|
|
|
|
|
|
|
print("\n7. Height comparison:") |
|
|
person1 = {"name": "Alice", "height": "5'6\""} |
|
|
person2 = {"name": "Bob", "height": "175cm"} |
|
|
|
|
|
alice_cm = converter.feet_to_cm(5, 6) |
|
|
bob_cm = 175 |
|
|
|
|
|
print(f" {person1['name']}: {person1['height']} = {alice_cm} cm") |
|
|
print(f" {person2['name']}: {person2['height']} = {bob_cm} cm") |
|
|
|
|
|
if alice_cm > bob_cm: |
|
|
print(f" {person1['name']} is taller by {alice_cm - bob_cm:.1f} cm") |
|
|
elif bob_cm > alice_cm: |
|
|
print(f" {person2['name']} is taller by {bob_cm - alice_cm:.1f} cm") |
|
|
else: |
|
|
print(f" They are the same height!") |
|
|
|
|
|
|
|
|
print("\n8. Error handling:") |
|
|
try: |
|
|
converter.feet_to_cm(-5, 10) |
|
|
except ValueError as e: |
|
|
print(f" Caught error: {e}") |
|
|
|
|
|
try: |
|
|
converter.parse_height_string("invalid input") |
|
|
except ValueError as e: |
|
|
print(f" Caught error: {e}") |
|
|
|
|
|
print("\n" + "=" * 60) |
|
|
print("Examples completed!") |
|
|
print("=" * 60) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|