Python中意外返回的变量

Python中意外返回的变量,python,string,function,Python,String,Function,我正在使用Python,我几乎已经编写了一些代码,作为所需任务的一部分 #------Unit converter------# #-------Challenge 5-------# #-------Definitions-------# def currencyConvert(): print("C") def tempConvert(): print("T") def massConvert(): print("M") def volConvert():

我正在使用Python,我几乎已经编写了一些代码,作为所需任务的一部分

#------Unit converter------#
#-------Challenge 5-------#
#-------Definitions-------#
def currencyConvert():
    print("C")

def tempConvert():
    print("T")

def massConvert():
    print("M")

def volConvert():
    print("V")

#-------Executions--------#
print("Welcome to my unit converter.\nIn this software, you can convert between the following things:")
print(" - Currency: United States Dollar (USD), Pound Sterling (GBP) and Serbian Dinar (RDS).")
print(" - Temperature: Fahrenheit (F) and Celsius (C)")
print(" - Mass: Pounds (lbs) and grams (mg/g/kg)")
print(" - Volume: Fluid ounces (fl oz) and litres (ml/cl/l")

def phaseOne():
    global unitType
    print("--------------------")
    unitType = input("What kind of conversion would you like to make? Currency (C), temperature (T), mass (M) or volume (V)?\n>>>")
    if unitType == "C" or "c":
        currencyConvert()
    elif unitType == "T" or "t":
        tempConvert()
    elif unitType == "M" or "m":
        massConvert()
    elif unitType == "V" or "v":
        volConvert()
    else:
        print("That is not a valid input. Please try again.")
        phaseOne()        

phaseOne()
我的问题是,当我运行程序并输入“V”时,我希望调用volConvert()函数(因此输出“V”),但它返回“C”。这是什么原因造成的

我还没有使用Python的技能,但我正在使用它,需要一些小的帮助


谢谢大家!

您拥有的条件作为
(unitType==“C”)或“C”
工作,而这不是您想要的。相反,您希望使用元组而不是列表来输入(“C”、“C”)

。节省内存,而且我相信速度更快。@NChauhan:我没有测量过,但我听到过类似的事情。我已经更新了我的答案。