【发布时间】:2017-04-21 23:12:42
【问题描述】:
虽然我正在学习 python,但我创建了这段代码,但问题是当有人键入不同于 stm 或 mts 的内容时,它只会打印错误消息并停止,我需要它继续并自行重新运行代码,所以我添加带有 continue 语句的 while 循环,但它不能正常工作,它只会不断发送错误消息,请任何想法如何让我的代码继续运行而不会发送垃圾消息或在它之后停止..非常感谢!
代码如下:
print("Welcome to MoroccanDirham_SaudiRiyal converter program!")
def mConv():
def rial_saudi_to_moroccan_dirham(sar):
amount = sar * 2.67
print("Here is the result: ", amount, "MAD")
def moroccan_dirham_to_rial_saudi(mad):
amount = mad * 0.37
print("Here is the result: ", amount, "SAR")
usChoice = str(input("For SAR to MAD type stm and for MAD to SAR type mts: "))
while True:
if usChoice == str("stm"):
x = int(input("Type the amount of money you want to convert: "))
rial_saudi_to_moroccan_dirham(x)
return False
elif usChoice == str("mts"):
y = int(input("Type the amount of money you want to convert: "))
moroccan_dirham_to_rial_saudi(y)
return False
elif usChoice != str("stm") or usChoice != str("mts") :
print("Error! Please choose between stm and mts.")
continue
return False
else:
return True
mConv()
【问题讨论】:
标签: python python-2.7 python-3.x wxpython ipython