1. # 注册
    2. userAccount = {'1001':{'password':'123456','balance':'10000','currency':'CNY','status':'active'},
    3. '1002':{'password':'111111','balance':'-200','currency':'CNY','status':'active'},
    4. '1003':{'password':'222222','balance':'2000000','currency':'CNY','status':'active'},
    5. '1004':{'password':'333333','balance':'8000000','currency':'CNY','status':'active'}
    6. }
    7. a = '2'
    8. while True:
    9. print('1.[登录]','2.[注册]',sep='\n')
    10. choice = input('请输入您的选择:')
    11. if choice == '2':
    12. user_id = input('请输入用户账号:')
    13. if user_id in userAccount:
    14. print('该账号已经存在,不能注册')
    15. else:
    16. user_password = input("请输入密码:")
    17. newSet = {user_id: {'password': user_password, 'balance': '0', 'currency': 'CNY', 'status': 'active'}}
    18. userAccount.update(newSet)
    19. elif choice == '1':
    20. log_id = input('请输入您的账号:')
    21. if log_id not in userAccount:
    22. print('您输入的账号不存在')
    23. else:
    24. for count in range(0, 3) :
    25. log_password = input("请输入密码:")
    26. if log_password != userAccount[log_id]['password']:
    27. print('您的密码错误,请重新输入')
    28. if count == 2:
    29. print('您的密码输入错误3次,请联系管理员')
    30. else:
    31. while True:
    32. print('【1. 查询】', '【2. 存款】', '【3. 取款】', '【4. 转账】', '【5. 返回】', sep='\n')
    33. choice2 = input('请输入您需要的功能:')
    34. if choice2 == '1':
    35. print('您的余额是:%s'%userAccount[log_id]['balance'])
    36. elif choice2 == '2':
    37. deposit = input('请输入存款金额:')
    38. deposit = int(deposit)
    39. user_balance = int(userAccount[log_id]['balance'])
    40. sum_balance = deposit + user_balance
    41. userAccount[log_id]['balance'] = str(sum_balance)
    42. print('您存入了%s'%deposit)
    43. print('你的余额是:%s'%userAccount[log_id]['balance'])
    44. elif choice2 == '3':
    45. cash = int(input('请输入取款金额'))
    46. user_balance = int(userAccount[log_id]['balance'])
    47. if cash > user_balance:
    48. print('您的余额不足')
    49. else:
    50. print(f'本次取款:{cash}')
    51. new_balance = user_balance - cash
    52. userAccount[log_id]['balance'] = str(new_balance)
    53. print('你的余额是:%s'%userAccount[log_id]['balance'])
    54. elif choice2 == '4':
    55. other_id = input('请输入需要转账的账号')
    56. if other_id not in userAccount:
    57. print('对方账号不存在')
    58. elif other_id == log_id:
    59. print('不能对自己转账')
    60. else:
    61. other_cash = int(input("请输入转账金额:"))
    62. user_balance = int(userAccount[log_id]['balance'])
    63. other_balance = int(userAccount[other_id]['balance'])
    64. if other_cash > user_balance:
    65. print('您的余额不足')
    66. else:
    67. print(f'本次转账:{other_cash}')
    68. new_balance01 = user_balance - other_cash # 我方余额
    69. userAccount[log_id]['balance'] = str(new_balance01)
    70. print('你的余额是:%s' % userAccount[log_id]['balance'])
    71. new_balance02 = other_balance + other_cash # 对方余额
    72. userAccount[other_id]['balance'] = str(new_balance02)
    73. elif choice2 == '5':
    74. break
    75. else:
    76. print('没有该功能,请重新选择!')
    77. break