Calculadora de unidades de alcohol
Calcula unidades de alcohol y calorías de bebidas, comparado con límites semanales de la OMS.
Preguntas Frecuentes
Implementación de Código
def calculate_alcohol_units(volume_ml: float, abv_percent: float) -> float:
"""
Calculate alcohol units using the UK standard formula.
1 unit = 10 mL (8 g) of pure ethanol.
"""
return (volume_ml * abv_percent) / 1000.0
# Example drinks
drinks = [
("Pint of 4% beer (568 mL)", 568, 4.0),
("Glass of 12% wine (175 mL)", 175, 12.0),
("Shot of 40% spirits (25 mL)", 25, 40.0),
("Can of 5% beer (330 mL)", 330, 5.0),
("Bottle of 5% beer (500 mL)", 500, 5.0),
]
print(f"{'Drink':<35} {'Units':>6}")
print("-" * 43)
for name, vol, abv in drinks:
units = calculate_alcohol_units(vol, abv)
print(f"{name:<35} {units:>6.2f}")
# Weekly tracker
weekly_drinks = [
(330, 5.0), # Mon - can of beer
(175, 12.0), # Wed - glass of wine
(500, 5.0), # Fri - bottle of beer
(25, 40.0), # Fri - shot
(175, 12.0), # Sat - glass of wine
]
total_units = sum(calculate_alcohol_units(v, a) for v, a in weekly_drinks)
recommended_limit = 14.0
print(f"\nWeekly total: {total_units:.2f} units")
print(f"Recommended limit: {recommended_limit} units/week")
if total_units <= recommended_limit:
print("Within recommended limits.")
else:
print(f"Exceeds limit by {total_units - recommended_limit:.2f} units.")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.