def JudgeNum(num):
for i in num:
if ord(i) < 48 or ord(i) > 57: # 数字对应的ASCII码
print('请输入正确的数字!')
return 0
return 1
def Transformation():
print('输入的货币类型是(美元/人民币):', end='')
money_type = input()
print(money_type)
if money_type == '人民币':
print('货币值为:¥', end='')
money = input()
while True:
if JudgeNum(money):
break
else:
print('货币值:¥', end='')
money = input()
print('人民币转换为美元后是:$', end='')
print(float(money) / 6.7766, end='')
print('美元')
elif money_type == '美元':
print('货币值为:$', end='')
money = input()
while True:
if JudgeNum(money):
break
else:
print('货币值:$', end='')
money = input()
print('美元转换为人民币后是:¥', end='')
print(float(money) * 6.7766, end='')
print('元')
elif money_type == 'end':
print('Over')
else:
print('unknown type or command ,please input it again ')
new_money_type = input()
Transformation(new_money_type)
def Cal_e():
e = 1.0
i = 1
while True:
temp = 1.0
for j in range(i):
temp *= (j + 1)
e += 1 / temp
i += 1
if 1 / temp < 0.000001:
break
print('e is: ', end='')
print(e)
def Judge_narcissistic_number():
judge_num = input('输入要判断的数:')
while True:
if JudgeNum(judge_num):
break
else:
judge_num = input('输入要判断的数:')
print(judge_num, end='')
if len(judge_num) != 3:
print('不是水仙花数')
return
temp = 0
for i in judge_num:
temp += int(i) * int(i) * int(i)
if int(temp) == int(judge_num):
print('是水仙花数')
else:
print('不是水仙花数')
if __name__ == '__main__':
while True:
cho = -1
print(' ____________')
print('|1 汇率转换器 |')
print('|2 计算e值 |')
print('|3 判断水仙花数|')
print('|4 退出 |')
print('|___________ |')
print('选择操作:', end='')
cho = input()
if int(cho) == 1:
print('---人民币-美元汇率转换器---')
Transformation()
elif int(cho) == 2:
print('---计算 e---')
Cal_e()
elif int(cho) == 3:
print('---判断水仙花数---')
Judge_narcissistic_number()
elif int(cho) == 4:
break
else:
print('不要乱输啊')