我是编程新手,我正在尝试在 python 中制作一个简单的单位转换器。我想将公制和公制内的单位转换为英制,反之亦然。我已经开始使用此代码,但发现此方法缓慢且效率低下,如何更有效地进行编码?
import math
import time
"""Unit Converter"""
#Welcome and variable setting
print ("Welcome to Sam's Unit Converter")
cat = raw_input ("Which category would you like to convert? we support length(l) and Weight(w): ")
if cat == ("l"):
unit1 = raw_input ("Which unit would you like to convert from: ")
unit2 = raw_input ("Which unit would you like to convert to: ")
num1 = raw_input ("Enter your value: " )
##Calculations
if unit1 == "cm" and unit2 == "m": …Run Code Online (Sandbox Code Playgroud)