首页 > 编程语言 > 详细

python开发一个菜单点菜功能,可以输入菜名前的数字编号点菜

时间:2020-05-03 11:58:07      阅读:105      评论:0      收藏:0      [点我收藏+]

 

import re
option_str = input("请输入数字或方向键:")
#re.sub(pattern,repl,string,count=0,flags=0)找到string中可以匹配pattern的部分,
#然后将这些部分替换成repl,本例就是将非数字的部分都去掉。
option = re.sub("\D","",option_str)
if int(option) == 1:
    print("选择数字1键执行的菜单")
if int(option) == 2:
    print("选择数字2键执行的菜单")
if int(option) == 3:
    print("选择数字3键执行的菜单")
if int(option) == 4:
    print("选择数字4键执行的菜单")
if int(option) == 5:
    print("选择数字5键执行的菜单")
if int(option) == 6:
    print("选择数字6键执行的菜单")
if int(option) == 7:
    print("选择数字7键执行的菜单")
if int(option) == 8:
    print("选择数字8键执行的菜单")
if int(option) == 0:
    print("退出系统")

结果:

请输入数字或方向键:5
选择数字5键执行的菜单

 

python开发一个菜单点菜功能,可以输入菜名前的数字编号点菜

原文:https://www.cnblogs.com/xiao02fang/p/12821282.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!