def _toForeignDollars_(renminbi):
to_us_dollars = 0.1546
to_eu_yuan = 0.1284
to_uk_pond = 0.1126
print("您输入的人民币金额为:", renminbi, "\n")
print("\t等值美元是:", "{:.2f}".format(float(renminbi * to_us_dollars)),
"\t等值欧元是:", "{:.3f}".format(float(renminbi * to_eu_yuan)),
"\t等值英镑是:", "{:.4f}".format(float(renminbi * to_uk_pond)))
def _is_renminbi_account(shuliang):
shulie = shuliang.split('.')
if len(shulie[0]) > 1:
shulie[0] = shulie[0].lstrip('0')
if shulie[0].isnumeric() and shulie[1].isnumeric() and len(shulie[1]) < 3:
return True
else:
return False
print("请输入正确的人民币金额,小数点最多2位")
shuliang_input = input()
shuliang_input.strip()
flag = 0
if not _is_renminbi_account(shuliang_input):
flag = 1
while flag == 1:
print("请输入正确的人民币金额,小数点最多2位")
shuliang_input = input()
_is_renminbi_account(shuliang_input)
if _is_renminbi_account(shuliang_input):
flag = 0
else:
flag = 1
_toForeignDollars_(float(shuliang_input))