Unit Converter
Convert selected length, mass, and temperature unit pairs. Students choose a valid branch and distinguish scale-only conversions from temperature offsets.
1# Take inputs2value = float(input("Enter value: "))3from_unit = input("From unit (km/m, kg/g, C/F): ")4to_unit = input("To unit (km/m, kg/g, C/F): ")56# Convert7if from_unit == 'km' and to_unit == 'm':8 result = value * 10009elif from_unit == 'm' and to_unit == 'km':10 result = value / 100011elif from_unit == 'kg' and to_unit == 'g':12 result = value * 100013elif from_unit == 'g' and to_unit == 'kg':14 result = value / 100015elif from_unit == 'C' and to_unit == 'F':16 result = (value * 9/5) + 3217elif from_unit == 'F' and to_unit == 'C':18 result = (value - 32) * 5/919else:20 result = "Invalid conversion"2122print(f"Result: {result}")
Output
Enter value: 5 From unit (km/m, kg/g, C/F): km To unit (km/m, kg/g, C/F): m Result: 5000.0
In this one
- Match ordered unit pairs
- Separate offsets from scaling
- Reject unsupported pairs
How it works
- 1
Read value and both unit labels.
- 2
Choose one of the six supported conversion branches.
- 3
Calculate its result or store Invalid conversion, then print.
Edge cases
Does km to kg work?
Does km to kg work?
No. It is not a supported conversion.
Does C to C return the original value?
Does C to C return the original value?
No. Same-unit cases are not implemented.
What's going on
Each branch matches both from_unit and to_unit. Length and mass pairs multiply or divide by one thousand; temperature pairs also account for the zero-point offset.
Only the listed pairs are supported. Labels are case-sensitive because no normalization occurs, and same-unit conversions are not included. The result is either a number or Invalid conversion. This is a small decision table, not a general dimensional-analysis library.
Does km to kg work? No. It is not a supported conversion.
Does C to C return the original value? No. Same-unit cases are not implemented.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why is Celsius-to-Fahrenheit not just scaling?
Pick an answer to check it.
Question 2
Does km to kg work?
Pick an answer to check it.
Questions people ask
Does km to kg work?
No. It is not a supported conversion.
Does C to C return the original value?
No. Same-unit cases are not implemented.
Why is Celsius-to-Fahrenheit not just scaling?
Its formula also adds 32.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum