python简单菜单_创建一个简单的python菜单

这篇博客演示了如何使用Python创建一个简单的交互式菜单,包括打印列表、添加名字、删除名字、更改列表项以及退出选项。通过用户输入来执行对应的操作,如使用append方法添加元素,remove方法移除元素,replace方法替换列表中的项。
摘要由CSDN通过智能技术生成

修正和评论,它们主要是语法错误。menulist= '''1. Print the list,

2. Add a name to the list,

3. Remove a name from the list,

4. Change an item in the list,

9. Quit''' #assuming you want to display menulist, having it as a tuple is useless

lst=("johny","tom","kim","tim","jim") #don't use reserved names for variables, may mess up things

target=raw_input("Pick an item from the menu:")

if target=="1": #this is an equality operator, whereas = is used to assign a variable (This checks the equality basically)

print lst

elif target=="2":

Addname=raw_input("Type in a name to add:")

list=list.append(Addname) #use append instead of insert, insert is for a specific position in list

print menulist #no parentheses, menulist is not a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值