zoukankan      html  css  js  c++  java
  • python开发一个菜单点菜功能,可以输入菜名前的数字编号点菜

      本例开发一个菜谱点菜功能,可以输入菜名前的数字编号点菜。 

    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键执行的菜单
  • 相关阅读:
    JAVA 线程安全与同步机制
    JAVA 多线程
    el-table 宽度自适应bug
    详解迭代器Iterator
    理解基本类型的溢出
    理解classpath
    I/O(一):基础知识
    C++: 智能指针
    C++: 值类别与移动语义基础
    CUDA 架构与编程概述
  • 原文地址:https://www.cnblogs.com/xiao02fang/p/12821282.html
Copyright © 2011-2022 走看看