{}
A Python course that doesn't leave you guessing. See every step with our code visualizer.
Try it yourself!
A Python course that doesn't leave you guessing. See every step with our code visualizer.
Try it yourself!
run-icon
main.py
def candle_wax_calculator(): print("🕯️ Candle Wax Calculator with Coconut Oil (Included in Wax)\n") try: num_candles = int(input("Number of candles: ")) container_size = float(input("Container size (oz): ")) fragrance_load = float(input("Fragrance load (%): ")) total_fill = num_candles * container_size fragrance_weight = total_fill * (fragrance_load / 100) # Initial wax weight (will include coconut oil) wax_plus_oil_weight = total_fill - fragrance_weight # Coconut oil: 0.5 tsp per 16 oz of wax blend (which includes coconut oil itself) # So we solve for coconut oil amount within wax_plus_oil_weight # Let x = coconut oil weight (oz) # Then wax weight = wax_plus_oil_weight - x # tsp = ((wax_plus_oil_weight - x) / 16) * 0.5 # But we need tsp = x * 6 (since 1 fl oz = 6 tsp), so: # x = ((wax_plus_oil_weight - x) / 16) * 0.5 / 6 # Solve for x numerically: def calculate_coconut_oil_weight(wax_total): # Estimate coconut oil by iterating x = 0.0 for _ in range(1000): # convergence loop coconut_oil_tsp = ((wax_total - x) / 16) * 0.5 x_new = coconut_oil_tsp / 6 if abs(x_new - x) < 0.0001: break x = x_new return x coconut_oil_oz = calculate_coconut_oil_weight(wax_plus_oil_weight) base_wax_weight = wax_plus_oil_weight - coconut_oil_oz coconut_oil_tsp = coconut_oil_oz * 6 coconut_oil_grams = coconut_oil_tsp * 4.5 print("\n--- Results ---") print(f"Total Fill Weight: {total_fill:.2f} oz") print(f"Fragrance Weight: {fragrance_weight:.2f} oz") print(f"Base Wax Weight: {base_wax_weight:.2f} oz") print(f"Coconut Oil:") print(f" • {coconut_oil_tsp:.2f} tsp") print(f" • {coconut_oil_oz:.2f} fl oz") print(f" • {coconut_oil_grams:.2f} grams") except ValueError: print("⚠️ Please enter valid numbers only.") if __name__ == "__main__": candle_wax_calculator()
Output