Type 100, Get 160.9 ā Build a Unit Converter (Beginner, Web App) in Python Tutorial
ā Runtime tested ā the solution passes every example case. š Full written solution: https://interview-kit-fe.vercel.app/project-build-a-unit-converter-beginner-web-app š» Code on GitHub: https://github.com/timepasshub2539-hue/leetcode-python/tree/main/project-build-a-unit-converter-beginner-web-app Chapters: 0:00 Type '100' ā Watch It Become 160.9 Instantly 0:11 Why Build a Unit Converter 0:30 Three Jobs, One File 0:48 The Form Markup 1:06 From Bare Markup to a Card 1:20 Length and Weight: One Base Unit 1:44 Temperature Needs Its Own Math 2:10 The Complete Converter 2:23 Wired Up Live 2:38 What Breaks It 3:01 Recap and What's Next 3:29 The Real Page, Running ā Runtime tested ā the solution passes every example case. š Full written solution: https://interview-kit-fe.vercel.app/project-build-a-unit-converter-beginner-web-app š» Code on GitHub: https://github.com/timepasshub2539-hue/leetcode-python/tree/main/project-build-a-unit-converter-beginner-web-app Chapters: 0:00 Type '100' ā Watch It Become 160.9 Instantly 0:11 Why Build a Unit Converter 0:30 Three Jobs, One File 0:48 The Form Markup 1:06 From Bare Markup to a Card 1:20 Length and Weight: One Base Unit 1:44 Temperature Needs Its Own Math 2:10 The Complete Converter 2:23 Wired Up Live 2:38 What Breaks It 3:01 Recap and What's Next 3:29 The Real Page, Running ā Runtime tested ā the solution passes every example case. š Full written solution: https://interview-kit-fe.vercel.app/project-build-a-unit-converter-beginner-web-app š» Code on GitHub: https://github.com/timepasshub2539-hue/leetcode-python/tree/main/project-build-a-unit-converter-beginner-web-app Chapters: 0:00 Type '100' ā Watch It Become 160.9 Instantly 0:11 Why Build a Unit Converter 0:30 Three Jobs, One File 0:48 The Form Markup 1:06 From Bare Markup to a Card 1:20 Length and Weight: One Base Unit 1:44 Temperature Needs Its Own Math 2:10 The Complete Converter 2:23 Wired Up Live 2:38 What Breaks It 3:01 Recap and What's Next 3:29 The Real Page, Running Type 100 and watch it become 160.9 instantly ā then build the web app that does it, from a bare HTML form to a fully wired converter. You'll learn why length and weight share one base-unit trick while temperature needs its own math, how to structure one file to do three jobs (markup, styling, logic), and what breaks the converter if you get the wiring wrong. By the end you'll have a real, running unit converter page and a clear plan for what to build next. #Python #WebDevelopment #CodingTutorial #BeginnerProject #LearnToCode Watch next: - Building My Own AI Developer Platform ā Ep 1: The idea: https://youtu.be/d-broARFYAY - Build a Unit Converter (Beginner, Web App) in Python ā Full Project Tutorial: https://youtu.be/0cAwwNRCkb8 - Building My Own AI Developer Platform ā Ep 2: AI architecture: https://youtu.be/GYVHVatRdhc
The solution
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; background: #1e1e2e; display: flex;
justify-content: center; align-items: center; height: 100vh; margin: 0; }
.card { background: #282838; padding: 24px 32px; border-radius: 12px;
color: #eee; width: 280px; }
select, input { width: 100%; padding: 8px; margin: 6px 0; border-radius: 6px;
border: 1px solid #444; background: #1e1e2e; color: #eee; }
#output { font-size: 1.2em; font-weight: bold; margin-top: 12px; }
</style>
</head>
<body>
<div class="card">
<select id="category">
<option value="length">Length</option>
<option value="weight">Weight</option>
<option value="temperature">Temperature</option>
</select>
<input id="value" type="text" placeholder="Enter a value">
<select id="fromUnit"></select>
<select id="toUnit"></select>
<p id="output">Result: --</p>
</div>
<script>
const LENGTH = { millimeter:0.001, centimeter:0.01, meter:1, kilometer:1000,
inch:0.0254, foot:0.3048, yard:0.9144, mile:1609.344 };
const WEIGHT = { milligram:0.001, gram:1, kilogram:1000, ounce:28.3495, pound:453.592 };
const TEMP = ['Celsius', 'Fahrenheit', 'Kelvin'];
const UNITS = { length: Object.keys(LENGTH), weight: Object.keys(WEIGHT), temperature: TEMP };
function toCelsius(v, unit) {
if (unit === 'Fahrenheit') return (v - 32) * 5/9;
if (unit === 'Kelvin') return v - 273.15;
return v;
}
function fromCelsius(c, unit) {
if (unit === 'Fahrenheit') return c * 9/5 + 32;
if (unit === 'Kelvin') return c + 273.15;
return c;
}
function convert(value, category, from, to) {
if (category === 'length') return value * LENGTH[from] / LENGTH[to];
if (category === 'weight') return value * WEIGHT[from] / WEIGHT[to];
return fromCelsius(toCelsius(value, from), to);
}
const categoryEl = document.getElementById('category');
const fromEl = document.getElementById('fromUnit');
const toEl = document.getElementById('toUnit');
const valueEl = document.getElementById('value');
const outputEl = document.getElementById('output');
function populateUnits() {
const units = UNITS[categoryEl.value];
fromEl.innerHTML = units.map(u => `<option>${u}</option>`).join('');
toEl.innerHTML = units.map(u => `<option>${u}</option>`).join('');
toEl.selectedIndex = 1;
update();
}
function update() {
const raw = valueEl.value.trim();
if (raw === '' || isNaN(raw)) {
outputEl.textContent = 'Result: --';
return;
}
const result = convert(Number(raw), categoryEl.value, fromEl.value, toEl.value);
outputEl.textContent = `Result: ${result.toFixed(4)}`;
}
categoryEl.addEventListener('change', populateUnits);
fromEl.addEventListener('change', update);
toEl.addEventListener('change', update);
valueEl.addEventListener('input', update);
populateUnits();
</script>
</body>
</html>Ready to try it yourself? Solve General problems with instant feedback in the practice sandbox.
Practice now ā


