python控制语句实验报告,python流程控制语句案例练习

最近玩python,为了更好的学习其中的流程控制语句,本身写了一个查询员工信息和更新信息的脚本,此脚本仅供练习使用。大拿可绕行!python

#!/usr/bin/env python

import sys

import os

os.system('clear')

mess = '''

\033[;35m ID :%s\033[0m

\033[;35m Name :%s\033[0m

\033[;35m Dep :%s\033[0m

'''

info = '''

\033[;32m+++++++++++++++++++++++++++++++++++++++++++\033[0m

\033[;32m++ Welcome to staffs infomation system ++\033[0m

\033[;32m+-----------------------------------------+\033[0m

\033[;32m+ +\033[0m

\033[;32m+ S: search staffs infomation +\033[0m

\033[;32m+ U: update staffs infomation +\033[0m

\033[;32m+ Q: quit +\033[0m

\033[;32m+ +\033[0m

\033[;32m+++++++++++++++++++++++++++++++++++++++++++\033[0m

'''

info2 = '''

\033[;32m+++++++++++++++++++++++++++++++++++++++++++\033[0m

\033[;32m+ A: Add staffs infomation +\033[0m

\033[;32m+ D: Del staffs infomation +\033[0m

\033[;32m+ Q: quit +\033[0m

\033[;32m+++++++++++++++++++++++++++++++++++++++++++\033[0m

'''

while True:

username = raw_input('\033[;32mPlease input your name: \033[0m').strip()

passwd = raw_input('\033[;32mPlease input password: \033[0m').strip()

if username != 'zhaohh' or passwd != '111111':

print ('\033[;31mYour username not exist or your password wrong!\033[0m')

continue

else:

print '\033[;32mHello zhaohh,Welcome!\033[0m'

break

os.system('sleep 2')

os.system('clear')

print info

while True:

user_input = raw_input("\033[;32mPlease select (S,U,default Q): \033[0m").strip()

# search staffs infomation

if user_input == "s" or user_input == "S":

staff_list = open("file.txt","rw")

c = staff_list.readlines()

staff_list.close()

while True:

inputs = raw_input('\033[;32mPlease input ID or name or dep: \033[0m').strip()

for line in c:

field = line.split()

if inputs in field:

print mess %(field[0],field[1],field[2])

break

else:

juge = raw_input('\033[;31mCan not found information! Continue? yes/no. \033[0m').strip()

if juge == 'yes' or juge == 'y':

continue

else:break

juge = raw_input('\033[;32mContinue search ? yes/no. \033[0m')

if juge == 'yes' or juge == 'y':

continue

elif juge == 'no' or juge == 'n' or juge == '':

sys.exit()

break

break

# add staffs infomation

elif user_input == "u" or user_input == "U":

print info2

while True:

update_input = raw_input('\033[;32mPlease select (A,D,default Q): \033[0m').strip()

if update_input == "a" or update_input == "A":

info_input = raw_input("\033[;32mPlease input user infomation: \033[0m")

staff_list = open("file.txt","a")

staff_list.write(info_input + '\n')

staff_list.close()

juge = raw_input('\033[;32mUpdate successful! Continue search ? yes/no. \033[0m')

if juge == 'yes' or juge == 'y':

continue

elif juge == 'no' or juge == 'n' or juge == '':

sys.exit()

# delete staffs infomation

elif update_input == "d" or update_input == "D":

inputs = raw_input('\033[;32mPlease input ID or name or dep: \033[0m')

f = open("newfile.txt","a")

staff_list = open("file.txt","rw")

for line in staff_list.readlines():

for field in line.split():

if inputs == field:

print '\033[;32mDelete successful!\033[0m'

break

else:

f.write(line)

staff_list.close()

f.close()

os.remove('file.txt')

os.rename('newfile.txt','file.txt')

juge = raw_input('\033[;32mContinue? yes/no. \033[0m')

if juge == 'yes' or juge == 'y':

continue

elif juge == 'no' or juge == 'n' or juge == '':

sys.exit()

elif update_input == "q" or update_input == "Q" or update_input == "":

sys.exit()

else:

print "\033[;31m Input error,try agin!\033[0m"

continue

elif user_input == "q" or user_input == "Q" or user_input == "":

sys.exit()

else:

print "\033[;31m Input error,try agin!\033[0m"

continue

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/430946.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux 文件重命名_如何在 Linux 上重命名一组文件 | Linux 中国

要用单个命令重命名一组文件,请使用 rename 命令。它需要使用正则表达式,并且可以在开始前告诉你会有什么更改。-- Sandra Henry-stocker几十年来,Linux 用户一直使用 mv 命令重命名文件。它很简单,并且能做到你要做的。但有时你需…

Spring 构造注入 传參数

1. 提供相应的构造方法 //构造器注入 public class Bean6 {private String name;private Integer age;// 服务于构造器注入使用public Bean6(String name, Integer age) {super();this.name name;this.age age;}public void show() {System.out.println("bean6:&…

php正则表达式函数案例,PHP正则表达式函数preg_replace用法实例分析

PHP正则表达式函数preg_replace用法。,具体如下:preg_replace 执行一个正则表达式的搜索和替换语法:preg_replace (pattern ,replacement ,subject,limit,count )参数描述pattern正则表达式(字符串或字符串数组)replacement用于替换的字符串或…

python tk protocol_Python Modbus_tk在树莓派上实现rtu master

利用 python modbus工具实现modbus从站的数据采集,很方便简单。Python Modbus 协议工具目前有下面三种:modbus_tk:完整modbus协议栈的实现,支持modbus tcp/rtu{1.提供slave模拟器,即模拟modbus server:502)…

根据另外一个表来更新,增加字段

update table1 set field1table2.field1,field2table2.field2from table2where table1.idtable2.id添加字段:alter table 表名 add 字段名 类型删除字段:alter table 表名 drop column 字段名转载于:https://www.cnblogs.com/yzwdli/p/5147512.html

html注册跳转php错误500,页面跳转后提示HTTP 异常 500(Internal Server Error):服务器尝试执行请求时遇到了意外情况...

页面跳转后提示HTTP 错误 500(Internal Server Error):服务器尝试执行请求时遇到了意外情况。index.php跳转到chkadmin.php提示(服务器错误网站在检索 http://localhost/shop/admin/chkadmin.php 时遇到错误。 该网站可能关闭进行维护或配置不正确。以下是一些建议&…

python爬虫运行不出结果_请问这个为什么就是爬不到,运行之后电脑卡的不行,求大佬指导...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼import requestsfrom multiprocessing import Poolimport reimport jsonfrom requests.exceptions import ConnectionErrordef get_to_html(url):try:headers {"User-Agent": "Mozilla/5.0 (compatible; MSIE 9.0;…

oracle插入性能优化,Oracle-insert性能优化

看见朋友导入数据,花了很长时间都没完成!其实有很多快速的方法,整理下! 向表中插入数据有很多办法,但是方法不同,性能差别很看见朋友导入数据,,花了很长时间都没完成!其实有很多快速…

python中setup什么意思_一个关于python3中setup.py小概念

一个关于setup.py小概念关于python setup.py bdistpython setup.py sdist两者的区别sdist 指的是source dist 即源码发布,带setup.pybdist 指的是built (binary) dist 即编译过(二进制)发布 不带setup.py查看setup.py各种编译命令参数python setup.py --help-c…

dba_segments和dba_tables的不同

create table tset as select * from dba_objects; select count(*) from tset; select table_name,blocks,empty_blocks from dba_tables where table_name’TSET’; select segment_name,bytes,blocks,extents from dba_segments where segment_name’TSET’; 问题来了&#…

oracle数sqlplus,sqlplus查询oracle数据库数据容量

登录sqlplus:cmd命令行登录:sqlplus orcl/orcl as sysdba查询表空间使用率select b.file_id  文件ID,b.tablespace_name  表空间,b.file_name     物理文件名,b.bytes       总字节数,(b.bytes-sum(nvl(a.bytes,0)))   已使用,sum(nv…

微博air客户端_打磨近十年,接近「完美」的 macOS 第三方微博客户端:Maipo

2020年11月13日,macOS Big Sur正式推送当天,Maipo for 微博也迎来了4.0.0大版本更新。从Weibo for Mac(2011年)、WeiboX(2014年)到Maipo(2017年),跨度近十年,…

oracle 匿名段,这段匿名块看着没什么问题啊

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼一旦执行,无限请求输入,怎么直接结束匿名块的执行而不是ctrlc退出sqlplusDeclarev_id teacher.teacher_id%Type:&teacher_id;v_name teacher.tname%Type:&tname;v_sex teacher.tsex%Type:&tsex;v_birth teacher.tbirth…

sqlserver查看被锁表、解锁

查看别锁表 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_typeOBJECT解锁方式: 1 declare spid int 2 Set spid 244 --锁表进程 3 declare sql varchar(1000) 4 set sqlkill ca…

python查看各列数据类型_pandas中查看数据类型的几种方式

在获得数据之后、分析数据之前,我们一般需要对数据总体进行一个概览,如有哪些字段,每个字段的类型,值是否缺失等,以下列出了几种方法,供我们方便快捷的查看dataframe的数据类型。1、维度查看:df…

sqlserver oracle插件,SQLServer链接服务器至Oracle

在SQL SERVER中访问ORACLE表的方法在SQL SERVER中,能否访问ORACLE表,进行查询操作呢?答案无疑是可以的,下面就为你介绍在SQL SERVER中访问ORACLE表的实现方法,供您参考。一、配置方法一:通过oracle的sql*ne…

输入框联动查询

目的&#xff1a;类似于百度的搜索联动&#xff0c;输入前面的几个字&#xff0c;查询出可能的结果供用户选择&#xff0c;如下&#xff1a; html部分&#xff1a;在“中”这个输入框下面隐藏一个ul属性&#xff0c;例如: <ul class"am-padding-left-0 uhide" id&…

python经纬度转换xy坐标公式_经纬度坐标转换为距离及角度(Python)

最近项目上有这样的需求&#xff0c;需要依据设备的经纬度坐标计算距离及角度。经验证后效果较好&#xff0c;并分享。1 经纬度转换距离代码#!/usr/bin/env python# -*- coding: utf-8 -*-__author__ Sevenimport math# 计算距离def getDistance(latA, lonA, latB, lonB):ra …

matlab铁路平板车装货问题,两辆铁路平板车的装货问题最终论文

两辆铁路平板车的装货问题摘要&#xff1a;铁路运输部门常常会遇到平板车的装货问题。包装箱的宽度和高度是一样的&#xff0c;厚度是不同的。每种装箱策略都会产生不同的浪费。本文所要讨论的就是怎样装箱&#xff0c;使得浪费最小。本题是个整数规划问题&#xff0c;其特点是…

LoadRunner函数

一、基础函数简介 在VU左边导航栏中&#xff0c;有三个LoadRunner框架函数&#xff0c;分别是vuser_init()、Action()、vuser_end()。这三个函数存在于任何Vuser类型的脚本中。 vuser_init:虚拟用户的初始化函数&#xff0c;一般将用户初始化的操作放在这里&#xff0c;如登录操…