python简单菜单_创建一个简单的python菜单
发布日期:2021-10-31 15:52:14 浏览次数:4 分类:技术文章

本文共 1398 字,大约阅读时间需要 4 分钟。

修正和评论,它们主要是语法错误。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 function; also this doesn't have to be indented

elif target=="3":

Removename=raw_input("What name would you like to remove:")

list=list.remove(Removename)

print menulist #again, I took the parentheses away

elif target=="4":

Changename=raw_input("What name would you like to change:") #you'd missed the " at the beginning

changetoname=raw_input("What is the new name:")

list=list.replace(Changename, changetoname) #removed the '. They're the variables, not the strings 'Changename' etc that you want to replace.

print menulist

elif target=="9":

print"good bye" #excessive indenting

else: #this replaces the initial while

#do nothing if the initial input is not 1,2,3,4 or 9

print menulist

转载地址:https://blog.csdn.net/weixin_39987847/article/details/114454920 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:rabbitmq怎么停止_Windows环境下RabbitMQ的启动和停止命令
下一篇:java oracle 字符_Oracle转义字符

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月13日 23时58分16秒