我正在使用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") or "c"
工作,而这不是你想要的。相反,您需要unittype in ("C", "c")
。你知道吗相关问题 更多 >
编程相关推荐