Python ATM模拟系统

花了半天把2.x的语法改成了3.x,补齐了部分功能

先说下遇到的几个区别:

1.print

2.x里   print "Hello World!!"

3.x里   print("Hello World!!!")

2.input

2.x里面用   raw_input()

3.x里只有  input()

3.字典的has_key()方法,python3以后删除了has_key()方法

2.x   dic.has_key(‘xxx‘)

3.x   key in dic

然后是思路,因为老师要求数据要永久保存,所以我用了两个txt文本,在程序启动前读入文本内容,在程序执行完毕后,将字典内容写入文本,代码如下

其他功能大概都是常规思路

#coding=utf-8
import os
#read txt into dic
User_Pwd = {}
User_Money={}
def open_User_Pwd():
    if(os.path.exists(‘User_Pwd_file.txt‘)):
        User_Pwd_file = open(‘User_Pwd_file.txt‘, ‘r‘)
        for line in User_Pwd_file:
            line = line.strip().split(‘:‘)
            User_Pwd[line[0]]=line[1]
        User_Pwd_file.close()
    else:
        User_Pwd_file = open(‘User_Pwd_file.txt‘, ‘w‘)
        User_Pwd_file.close()

def open_User_Money():
    if(os.path.exists(‘User_Money_file.txt‘)):
        User_Money_file = open(‘User_Money_file.txt‘, ‘r‘)
        for line in User_Money_file:
            line = line.strip().split(‘:‘)
            User_Money[line[0]] = line[1]
        User_Money_file.close()
    else:
        User_Money_file=open(‘User_Money_file.txt‘,‘w‘)
        User_Money_file.close()

# write User-password into txt
def Write_User_Pwd():
     User_Pwd_file = open(‘User_Pwd_file.txt‘,‘w‘)
     for key in User_Pwd:
        User_Pwd_file.write(key +":" + User_Pwd[key]+‘\n‘)
     User_Pwd_file.close()

#write User-Money into txt
def Write_User_Money():
     User_Money_file=open(‘User_Money_file.txt‘,‘w‘)
     for key in User_Money:
         User_Money_file.write(key +":" +str(User_Money[key])+‘\n‘)
     User_Money_file.close()

def MainMeun():
    open_User_Pwd()
    open_User_Money()
    print("=====欢迎使用蜗牛ATM无限制存取款系统=====")
    print("===请输入选项:1.登陆  2.注册 3.退出===")
    print("=========================================")
    choice =input()
    if choice==‘1‘:
        print("=====欢迎来到登录模块=====")
        login()
    elif choice==‘2‘:
        print("=====欢迎来到注册模块=====")
        register()
    elif choice==‘3‘:
        print("=====你即将退出系统=====")
        exit()
    else:
        print("=====请输入正确的选项=====")
        MainMeun()

#login
def login():
        UserName = input("请输入您的账号:").strip()

        n=0
        t=0

        while (n<2):
           if (not UserName in User_Pwd):
                n=n+1
                print ("对不起,请重新输入")
                UserName = input("请输入您的账号:").strip()
           else:
               if(t>2):
                   exit()
               else:
                   UserPassword = input("请输入您的密码 :").strip()
                   if(not User_Pwd[UserName]==UserPassword):
                       t=t+1
                       print ("对不起,请重新输入")
                   else:
                       global CurrentName
                       CurrentName = UserName
                       level_two()
                       break

#level_two
def level_two():
    print ("请输入选项")
    print("1.查询余额 \n" "2.转账\n"
          "3.取现\n""4.存钱\n"
           "5.回到主菜单\n""6.退出"
          )
    choice2=input()
    if (choice2==‘1‘):
        print("=====查询余额=====")
        CheckBalance()
    elif(choice2==‘2‘):
        print ("=====转账=====")
        MoneyTransfer()
    elif(choice2==‘3‘):
        print("=====取现=====")
        getcash()
    elif(choice2==‘4‘):
        print("=====存钱=====")
        savecash()
    elif(choice2==‘5‘):
        print("=========================================")
        MainMeun()
    elif(choice2==‘6‘):
        exit()
    else:
        print("请输入正确的选项:")
        level_two()

#1.check the balance
def CheckBalance():
    UserName =input("请输入账户:")
    if (UserName in User_Money):
        print("当前账户是 " + UserName)
        print ("当前余额是 " + User_Money[UserName])
        print ("-------------------------------------------------------------------")
        level_two()
    else:
        print("请输入正确的账号")
        CheckBalance()

#2.转账
def MoneyTransfer():
    print("当前的账户是 " + CurrentName)
    TransferName=input("请输入要转入的账号: ")
    if(TransferName in User_Money and not CurrentName==TransferName):
        TransferMoney=input("请输入要转入的金额: ")
        if(TransferMoney.isdigit() and int(User_Money[CurrentName])>=int(TransferMoney)):
            User_Money[CurrentName]= int(User_Money[CurrentName])-int(TransferMoney)
            User_Money[TransferName]=int(User_Money[TransferName])+int(TransferMoney)
            Write_User_Money()
            print(CurrentName + "余额是 " + str(User_Money[CurrentName]))
            print(TransferName+ "余额是 " + str(User_Money[TransferName]))
            level_two()
        else:
            print("!!!!!!!!!!!!!请输入正确的金额!!!!!!!!!!!")
            MoneyTransfer()
    else:
        print("!!!!!!!!!!!!!!请输入正确的用户名!!!!!!!!!!!!!!!")
        MoneyTransfer()

#取现
def getcash():
    print("当前账号是:"+ CurrentName)
    print("当前的余额是:"+str(User_Money[CurrentName]))
    num = input("请输入取现金额:")
    if(num.isdigit()):
        if(int(User_Money[CurrentName])>=int(num) and int(num)>0):
            User_Money[CurrentName]=int(User_Money[CurrentName])-int(num)
            Write_User_Money()
            print("取现后剩余金额:" + str(User_Money[CurrentName]))
            level_two()
        else:
            print("余额不足!!!")
    else:
        print("请输入数字!!!")

#存钱
def savecash():
    print("当前账号是:" + CurrentName)
    print("当前的余额是:" + str(User_Money[CurrentName]))
    num = input("请输入存入金额:")
    if (num.isdigit() and int(num) > 0):
        User_Money[CurrentName] = int(User_Money[CurrentName]) + int(num)
        Write_User_Money()
        print("存入后剩余金额:" + str(User_Money[CurrentName]))
        level_two()
    else:
        print("输入错误!!!")
        print(‘---------------------------------------------------------‘)
        level_two()

#register
def register():
    UserName=input("请输入用户名:")
    if UserName in User_Pwd:
        print("用户名已存在,请重新输入")
        register()
    else:
     UserPwd=input("请输入密码:")
     User_Pwd[UserName] = UserPwd
     User_Money[UserName]=int(5000)
     print("恭喜你,注册成功")
     print("Your User Name is " + UserName)
     print ("You have money:$5000")
     Write_User_Pwd()
     Write_User_Money()
     MainMeun()

MainMeun()
时间: 2024-08-29 02:31:58

Python ATM模拟系统的相关文章

d3_3 ATM模拟系统

#include<stdio.h> #include<stdlib.h> int x;//保存客户ID(index值) void login(); //登录 void menu(); //菜单 void deposit(); //存款 void withdraw();//取款 void check(); //查询 void quit(); //退卡 struct User { char name[10]; int account; short password; int money

python atm小脚本

用python写的一个自助信用卡的小脚本,有'取现,查询记录,转账,还款,购物'功能,用到了picked序列化,prettytable等功能 下面是测试和代码 [email protected]:~# python atm.py  plz enter your card id: 0000 plz enter your password:                                      欢迎登录信用卡系统!             可选操作:               

python ATM购物程序

需求: 模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日,过期未还,按欠款总额 万分之5 每日计息 支持多账户登录 支持账户间转账 记录每月日常消费流水 提供还款接口 ATM记录操作日志 提供管理接口,包括添加账户.用户额度,冻结账户等.. 此需求因第一次接触,所以全是借鉴网友的blog 一.程序具体说明: 一.主程序day5_credit_card.py开始 1.生成

python ATM项目

1.需求: 指定最大透支额度 可取款 定期还款(每月指定日期还款,如15号) 可存款 定期出账单 支持多用户登陆,用户间转帐 支持多用户 管理员可添加账户.指定用户额度.冻结用户等 购物车: 商品信息- 数量.单价.名称 用户信息- 帐号.密码.余额 用户可充值 购物历史信息 允许用户多次购买,每次可购买多件 余额不足时进行提醒 用户退出时 ,输出当次购物信息 用户下次登陆时可查看购物历史 商品列表分级显示 参考ygqygq2  https://gitee.com/ygqygq2/python_

python ATM + 购物车

一.项目介绍 ATM + 购物商城程序其实是通过模拟银行ATM机功能以及电商平台<购物商城程序>功能的实现,将前面大部分所学的知识点串联起来, 更好的去巩固python基础.这也是在学习python这门语言的第一个程序. 项目需求如下: - 额度 15000或自定义 - 实现购物商城,买东西加入 购物车,调用信用卡接口结账 - 可以提现,手续费5% - 支持多账户登录 - 支持账户间转账 - 记录每月日常消费流水 - 提供还款接口 - ATM记录操作日志 - 提供管理接口,包括添加账户.用户额

Python ATM

# ATM 模拟实现# 功能:# 输入对应的数字进入不同的功能:# 1. 支持进入商城购物,并通过信用卡结账.# 2. 支持信用卡余额查询.# 3. 支持不同用户之间的转账.# 4. 支持账单还款(充值功能).# 5. 支持查看账单详情.# 6. 支持用户登入密码修改. #################################################### Welcome To ATM! ## ## 1.进入商城 2.余额查询 ## 3.账户转账 4.账单还款 ## 5.账户管

Python学习day5作业-ATM和购物商城

Python学习day5作业 Python学习day5作业 ATM和购物商城 作业需求 ATM: 指定最大透支额度 可取款 定期还款(每月指定日期还款,如15号) 可存款 定期出账单 支持多用户登陆,用户间转帐 支持多用户 管理员可添加账户.指定用户额度.冻结用户等 购物车: 商品信息- 数量.单价.名称 用户信息- 帐号.密码.余额 用户可充值 购物历史信息 允许用户多次购买,每次可购买多件 余额不足时进行提醒 用户退出时 ,输出当次购物信息 用户下次登陆时可查看购物历史 商品列表分级显示 1

Python实现atm机的功能

主要还是参考网上内容,自己做了修改.虽然代码有小bug,但是不影响学习和测试. 功能: 额度:8000 可以提现,手续费5% 每月最后一天出账单,写入文件 记录每月日常消费流水 提供还款接口 1.atm的脚本 [[email protected] atm]# cat atm.py #!/usr/bin/env python # -*- coding: utf-8 -*- ''' Date:2017-03-23 Author:Bob ''' import os import time import

python第二十三天-----作业中

1 #!usr/bin/env python 2 #-*-coding:utf-8-*- 3 # Author calmyan 4 import os ,sys,time 5 6 from core import transaction #包含记账\还钱\取现等所有的与账户金额相关的操作 7 from core import user_pass #用户名检测相关 8 from core import log_file #日志相关 9 10 11 def login():#开始函数 12 # ti