python自学篇九[ 函数(三):变量作用域+ATM+5个小练习]

Python练习项目——模拟ATM机登录系统 一、题目要求: 通过Python编程完成一个银行ATM机模拟系统,具备如下功能: (1)登陆验证:用户输入用户名密码登陆,检测用户名是否存在以及用户名密码是否匹配;用户名密码各有三次输入机会,超过三次系统退出。 (2)菜单界面:登陆成功后显示功能操作界面,输入序号选择对应功能。 (3)用户注册:用户可以输入用户名和密码创建自己的账号,并输入电话号码等信息,如果用户名存在则让用户重新输入用户 阅读详情

python基础系列:
python自学篇一[ Anaconda3安装 ]
python自学篇二[ pycharm安装及使用 ]
python自学篇三[ 判断语句if的使用 ]
python自学篇四[ 基本数据类型和字符串常用处理 ]
python自学篇五[ 列表 ]
python自学篇六[ 元组 ]
python自学篇七[ 字典+深拷贝与浅拷贝 ]描述
python自学篇八[ 循环:while+for+pass+range()+推导式 ]
python自学篇九[ 函数(一):参数+对象 ]
python自学篇九[ 函数(二):返回值return+yield+迭代器+生成器 ]
python自学篇九[ 函数(三):变量作用域+ATM+5个小练习 ]
python自学篇九[ 函数(四):递归函数+匿名函数+内置函数+高阶函数 ]
python自学篇十[ 面向对象 (一) :面向对象概念+定义类+练习一]
python自学篇十[ 面向对象 (二) :继承+多继承+类属性+实例属性]
python自学篇十[ 面向对象 (三) :访问限制+类方法+静态方法]
python自学篇十[ 面向对象 (四) :王者荣耀小游戏+模拟一个简单的银行进行业务办理的类]
python自学篇十一[ 模块简介+模块制作+dir()函数+标准模块+包]
python自学篇十二[ 文件:打开+读取+写入+3个习题]

变量的作用域

  • 个程序的所有的变量并不是在哪个位置都可以访问的。访问权限决定于这个变量是在哪里赋值的。

  • 定义在函数内部的变量拥有一个局部作用域,定义在函数外的拥有全局作用域

  • 变量的作用域决定了在哪一部分程序你可以访问哪个特定的变量名称。两种最基本的变量作用域如下:

局部变量:声明在函数内部的变量是局部变量,局部变量的作用于只在于函数中,外部无法使用
  • 不同的函数,可以定义相同的名字的局部变量,但是各用个的不会产生影响
全局变量:声明在函数外部的变量,定义在函数外的拥有全局作用域
  • 对于可变类型的全局变量来说,要在函数中修改可以不使用global声明
  • 对于不可变类型的全局变量来说,要在函数中修改需要global声明
  • 在函数内部修改全局变量需要使用grobal关键字声明
global 变量名

函数习题

ATM取款机
  • 第一个方法(世界复杂的比第二个大):
'''
    ATM取款机
'''
    #1.登录验证
def login(password):
    pwd='88888888'#初始密码88888888
    if password==pwd:
        return True
    else:
        return False

    #金额验证
def checkmoney(money):
    if money.isdigit():
        if int(money)%
Python 实例详解:银行 ATM 等待时间分析 这是一道 Python 面向对象编程的实例,包含面向对象编程、Class 类相关知识,请读者先自行掌握。本文分析已有代码,主要理解其中逻辑,学习编程方法。代码乍看之下稍微复杂,拆解之后,弄通逻辑,还是很清晰明了的。 前部分为代码分析,可以重点看后面的程序运行部分哈,配合图文,便于理解。 这是笔者第一次写实例分析,内容详细,篇幅较长,仅用于学习与交流。若有疏漏,请多包涵,欢迎各位指点和讨论啊~ 【需... 阅读详情

相关推荐

python自学篇一[Anaconda3安装]

一.python自学篇一[Anaconda3安装] Anaconda是什么 Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便地解决多版本python并存、切换以及各种第三方包安装问题。Anaconda利用工具/命令conda来进行package和environment的管理,并且已经包含了Python...

Web_Student的博客 1129

python自学篇十二[ 文件:打开+读取+写入+文件夹+3个习题]

文章目录一.文件的操作1.文件的打开open函数参数文件读写with…open访问模式2.文件的关闭close()函数二.文件的读取1.文件的读取readlines()用open结合for循环逐行读取with结合for逐行读取用open结合for,readlines循环逐行读取2.文件的写入写入文件写的方式打开一个文件写入内容到文件中tell查看文件指针seek设置指针常用函数四.习题 一.文件的...

Web_Student的博客 1832

基于python的ATM(自动取款机)项目

用python写了一个ATM(自动取款机),共有十种功能,可用作大学生大作业。 具体实现效果: 还有很多功能没有展示,源代码地址:添加链接描述

weixin_52134263的博客 8040

手把手教你在Keil/IAR中移植SEGGER_RTT组件(避坑指南+性能对比)

本文详细介绍了在Keil/IAR开发环境中移植SEGGER RTT调试组件的完整流程与优化技巧。通过对比传统串口调试,SEGGER RTT凭借零硬件占用、高速传输和双向交互等优势,显著提升嵌入式开发效率。文章包含配置步骤、性能调优方案及常见问题解决方案,是嵌入式开发者必备的实用指南。

y7z8a的博客 243

从0开始写Vue项目-环境和项目搭建

什么是VueVue.js - 渐进式 JavaScript 框架 | Vue.js (vuejs.org)2.介绍与描述动态构建用户界面的渐进式JavaScript框架作者:尤雨溪3.Vue的特点遵循MVVM模式编码简洁,体积小,运行效率高,适合移动/PC端开发它本身只关注UI,可以引入其它第三方库开发项目4.与其他JS框架的关联借鉴 Angular 的模板和数据绑定技术借鉴 React 的组件化和虚拟DOM技术5.Vue周边库vue-cli:vue脚手架axios。

不愧是暮言的博客 1483

【突变检验合集】含Pettitt突变检验等

突变检验方法合集

WW、forever的博客 3534

Cesium中级开发教程之五十二:气泡弹窗

支持多种交互方式触发气泡弹窗显示,如鼠标悬停、点击地图上的特定元素(像实体、标注、模型等)。例如,当用户鼠标悬停在一个表示城市的点上时,弹出显示该城市名称、人口等信息的气泡。:依据特定的数据条件或业务逻辑触发。比如,当某个区域的气象数据达到一定阈值时,自动弹出显示相关气象预警信息的气泡。

664

<IBM AIX> 《HACMP 实用手册和命令 HA切换手册》 - 鸿篇巨制,全网最全

操作命令检查磁盘预留策略要将磁盘预留策略更改为 no_reserve集群状态实用程序查看集群状态是否正常SMIT System Management (C-SPOC)Cluster ServicesShow Cluster Services 面板上的选项或 lssrc 命令查看资源组、资源组对应的VG、资源组对应的APPLICATION SERVER# ./cldispsmit常用命令F3退出F4列表Esc+6或者F6查看命令Esc+7或者F7选择多项检查状态。

Else 的博客 3363

ZYNQ Petalinux编译系统启动文件实战指南

本文提出的混合编译加速方案实测可将编译时间从45分钟缩短至18分钟,QSPI双启动方案已在工业控制领域成功应用。Xilinx官方UG1144文档(最新v2023.1版)正点原子《ZYNQ嵌入式开发实战》开源项目Meta-Petalinux(GitHub趋势项目)未来展望:随着Versal平台的普及,Petalinux将支持更多AI加速器原生驱动,值得持续关注。

QQ_778132974的博客 812

56、CAN总线RC低通滤波器截止频率计算与实战

本文详细探讨了CAN总线RC低通滤波器的设计与应用。作者通过实际项目案例,分析了CAN总线噪声频谱特性,提出截止频率计算的"黄金法则",强调需考虑收发器输入阻抗的并联效应。文章给出RC参数选择的经验值(R=100Ω-1kΩ,C=10pF-100pF),并指出PCB布局的关键要点:RC应紧贴收发器引脚,电容接地端需直接连接地平面。最后建议结合示波器和眼图验证效果,并提醒RC滤波器只是抗干扰方案的一部分,良好的PCB布局设计才是根本。

2401_88858637的博客 70

华为交换机系统软件升级和安全漏洞修复教程

在华为交换机国网可以查询到华为交换机官方电话:400-822-9999,通过下命令查询出需要升级的交换机软件版本和补丁版本号发给华为,获取新的升级系统软件和补丁以及升级教程。下面是我升级华为交换机总结的教程,作为参考。...

星如雨落 2965

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: python自学篇九[ 函数(二):返回值return+yield+迭代器+生成器]
下一篇: python自学篇九[ 函数(四):递归函数+匿名函数+内置函数+高阶函数]
目遇之而成色
博客等级 码龄7年 59粉丝 56原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值