Python中意外的返回变量

2024-09-27 09:34:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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方面的技能,但我正在研究它,需要一些小的帮助。你知道吗

谢谢你!你知道吗


Tags: orandtoyoudefcurrencyconverterprint

热门问题