python实现简单的名字管理系统_python列表使用实现名字管理系统

python列表使用实现名字管理系统

来源:中文源码网    浏览: 次    日期:2019年11月5日

【下载文档:  python列表使用实现名字管理系统.txt 】

(友情提示:右键点上行txt文档名->目标另存为)

python列表使用实现名字管理系统本文实例为大家分享了python列表使用实现名字管理系统的具体代码,供大家参考,具体内容如下

实现的功能代码如下:

# 名字管理系统 列表的使用

print("="*50)

print("1:添加名字")

print("2:修改名字")

print("3:查询名字")

print("4:删除名字")

print("5:退出")

print("="*50)

names = []

while True:

num = int(input("请输入要操作的序号:")) # input获取到的是str,要转换为Int

if num == 1:

name_add = input("请输入要添加的名字:")

names.append(name_add)

print(names)

elif num == 2:

name_edit1 = input("请输入要修改的原始名字")

# 法一:

# if name_edit1 in names:

# for i in range(len(names)):

# if name_edit1 == names[i]:

# name_edit2 = input("请输入要修改为的名字:")

# names[i] = name_edit2

# print("修改成功!")

# else:

# print("查无此人")

# 法二:

find_name = 0 # 默认没找到

for i in range(len(names)):

if name_edit1 == names[i]:

name_edit2 = input("请输入要修改为的名字:")

names[i] = name_edit2

print("修改成功!")

find_name = 1

if find_name = 0:

print("查无此人")

elif num == 3:

name_select = input("请输入要查询的名字:")

if name_select in names:

print("找到了要查找的人")

else:

print("查无此人")

elif num == 4:

name_del = input("请输入要进行删除的名字:")

if name_del in names:

names.remove(name_del)

print("删除成功!")

else:

print("查无此人,无法进行删除")

elif num == 5:

break

else:

print("输入错误!")

小编再为大家分享另一段用python中列表实现名字管理系统的代码:1、打印功能提示

2、获取用户输入

3、根据用户的输入选择相应的功能进行实现#打印提示

print("="*50)

print("names_manage_systme")

print("1、add a new name")

print("2、delete a name")

print("3、modify a name")

print("4、search a name")

print("5、quit!")

print("="*50)#存储用户姓名

names = []while True:

#获取用户输入

user_input_num = int(input("please input the number you need:"))

#功能实现

if user_input_num == 1: #增加

new_name = input("please input the new name that you need to add:")

names.append(new_name)

print(names)

elif user_input_num == 2: #删除

del_name = input("please input the new name that you need to delete:")

names.remove(del_name)

print(names)

elif user_input_num == 3: #改

modify_name = input("please input the new name that you need to modify:")

after_modify_name = input("please input the new name :")

length = len(names)

modify_name_index = 0

i = 0

while i < length:

if modify_name == names[i]:

modify_name_index = i

break

i += 1

names[modify_name_index] = after_modify_name

print(names) elif user_input_num == 4: #查找

search_name = input("please input the new name that you need to search:")

length = len(names)

search_name_index = 0

i = 0

while i < length:

if search_name == names[i]:

search_name_index = i

break

i += 1

if i == length:

search_name_index = -1 #没有找到的话令索引置为-1

print("the index of your search_name is:%d"%search_name_index) elif user_input_num == 5: #退出

print("quit success!")

break

else:

print("input number wrong!\nplease input again")以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持中文源码网。

亲,试试微信扫码分享本页! *^_^*

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

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

相关文章

ssm项目搭建

系统环境搭建 Spring的jar包11个 com.springsource.org.aopalliance-1.0.0.jar //Aopi联盟的jar包遵循其规则 com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar //面向切面编程 spring-aop-5.0.1.RELEASEjar //实现aop spring-aspects-5.0.1.RELEASEjar //aspect整合的…

【计算机网络】——习题解析:一个UDP用户数据的数据字段为8192字节,在数据链路层要使用以太网来传输,试问应当划分为几个IP数据报片?说明每一个IP数据报字段长度和片偏移字段的值

【计算机网络】——习题解析&#xff1a;一个UDP用户数据的数据字段为8192字节&#xff0c;在数据链路层要使用以太网来传输&#xff0c;试问应当划分为几个IP数据报片&#xff1f;说明每一个IP数据报字段长度和片偏移字段的值 答&#xff1a;6个数据字段的长度&#xff1a;前5…

java网络接口_java网络编程之识别示例 获取主机网络接口列表

importjava.net.*;importjava.util.Enumeration;publicclassInetAddressExample{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubtry{//获取主机网络接口列表EnumerationinterfaceListNetworkInterface.getNetworkInterfaces();//检测接口列表是否为空,即使…

网络协议,各层功能,各层协议

一、OSI七层模型 OSI七层协议模型主要是&#xff1a;应用层&#xff08;Application&#xff09;、表示层&#xff08;Presentation&#xff09;、会话层&#xff08;Session&#xff09;、传输层&#xff08;Transport&#xff09;、网络层&#xff08;Network&#xff09;、数…

vc2010 mysql5.7_VC2010利用MySQL++访问mysql. 及连接池示例

参加这个哥们的博客http://www.voidcn.com/article/p-mfnvxzca-cd.html 我的一个测试例子&#xff0c;用到了blob&#xff1b; #include #include #include #include #include using namespace mysqlpp; using namespace std; sql_create_3(sorttest,1,3,sql_int_unsigned,id,s…

java中下拉框select和单选按钮的回显操作

1.下拉框select的回显 <select name"departmentId" id"departmentId"><option value"0">请选择部门</option><c:forEach items"${departmentList }" var"department"><!-- 下拉框回显 -->&l…

fastdfs java token_fastdfs-client-java操作fastdfs

一、在https://github.com/happyfish100/fastdfs-client-java 下载客户端&#xff0c;解压后并执行ant命令&#xff0c;在E:\tools\libs\fastdfs\fastdfs-client-Java-master\src\build下会生成fastdfs_client.jar如图示二、mvn安装fastdfs_client.jar&#xff0c;在cmd中执行命…

idea编辑器中使用@Data注解无效解决办法

使用Data注解可以减少了以前的get和set等方法&#xff0c;但是在idea编辑器中不认识会在使用实体类元素时候找不到&#xff08;但是运行不会报错&#xff09; 所以可以添加插件

java spring 加载顺序_java – 如何执行spring配置类的加载顺序?

我正在一个多模块项目(maven)上使用spring-boot.每个模块都有自己的Configuration类.基本上我确实有如下的布局模块嵌入式(运行只调用SpringApplication.run())方法&#xff1a;ConfigurationEnableAutoConfigurationComponentScan("de.foobar.rootpackage")Import({…

@Mapper和@Repository的区别

Mapper和Repository的区别 1.相同点 Mapper和Repository都是作用在dao层接口&#xff0c;使得其生成代理对象bean&#xff0c;交给spring 容器管理 对于mybatis来说&#xff0c;都可以不用写mapper.xml文件 2.不同点 Mapper不需要配置扫描地址&#xff0c;可以单独使用&#x…

java xstream jar_Java库使用----xstream1.3.1

package com.xstream;import java.util.Map;/*** XStream可以自动生成相关的xml配置*/public class XstreamTest{private String moduleName;private Map env;public String getModuleName(){return moduleName;}public void setModuleName(String moduleName){this.moduleName…

在Spring Boot + Mybatis 中,使用@Repository失效

在Spring Boot Mybatis 中&#xff0c;使用Repository失效 在springboot 中&#xff0c;给mapper的接口上加上Repository&#xff0c;无法生成相应的bean,从而无法Autowired&#xff0c;这是因为spring扫描注解时&#xff0c;自动过滤掉了接口和抽象类&#xff0c;这种情况下可…

java中arg函数_main函数必须要带参数(String[] args)吗?

String[] args是main函数的形式参数,可以用来获取命令行用户输入进去的参数。java 本身不存在不带String args[]的main函数&#xff0c;java程序中去掉String args[]会出现错误。建个test类 在cmd中运行时输入java test a b c,并且在你的main函数里面加这段话&#xff1a;Syste…

git本地库(操作具体命令)

在任何盘符下创建本地仓库repository&#xff08;除git目录下&#xff09; 在项目目录创建新的本地仓库&#xff0c;并把项目里的所有文件全部添加、提交到本地仓库中去&#xff1a; $ git init #在当前的目录下创建一个新的空的本地仓库 Initialized empty Git repository…

用java做一个小游戏源代码_用java编写的小游戏源代码分析

用java编写的小游戏源代码分析1/5/2008人气&#xff1a;12951import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;public class GreedSnake implements KeyListener{JFrame mainFrame;Canvas paintCanvas;JLabel labelScore;SnakeModel snake…

idea右键项目没有git 【解决方法】

右键项目&#xff0c;没有git选项 解决方法&#xff1a; 进入settings,然后搜索version,按下图点击即可&#xff1a; over&#xff0c;解决&#xff1a;

java注解执行顺序_如何确保java中的注释执行顺序?

您可以使用Order注释确保自定义注释的顺序.例&#xff1a;第一个注释&#xff1a;Retention(RetentionPolicy.RUNTIME)Target(ElementType.METHOD)public interface CustomAnnotation {}AspectComponentOrder(value 1)public class CustomAnnotationInterceptor {Before("…

用java设计秒表_运用Java编写 秒表程序

import java.awt.*;import java.awt.event.*;import javax.swing.*;public class SecondJFrame extends JFrame implements ActionListener,FocusListener{ //响应单击、焦点事件private JTextField text;private JB…

GIT commit问题 No errors and 30 warnings found. Would you like to review them?

GIT commit问题 No errors and 30 warnings found. Would you like to review them?

java spring 条件注解_【Spring】Spring高级话题-条件注解-@Condition

进行本示例的演示&#xff0c;需要先配置好Maven和Spring哦、见:【Spring】基于IntelliJ IDEA搭建Maven分析通过profile&#xff0c;我们可以获得不同的profile&#xff0c;我们可以获得不同的Bean。Spring4提供了一个更通用的基于条件的Bean的创建&#xff0c;即使用Condition…