zoukankan      html  css  js  c++  java
  • 练习

    识别三次

    #!/usr/bin/env python
    import sys
    
    my_age=28
    count = 0
    
    def num(nums):    
        global count
        while count < 3:
    
            user_input = int(input("input your guess num:"))
            if user_input == my_age:
                print 'successful. you go it!!!'
                sys.exit(0)
            elif user_input < my_age:
                print 'small'
            else:
                print 'bigger'
            count +=1
            if count >2:
                print 'sb'
    
    if __name__ == '__main__':
        num('nums')
    View Code
    #!/usr/bin/ env python
    # -*- coding: UTF-8 -*-
    
    stack = []
    
    def pushit():
        stack.append(raw_input('enter new string:    '))
    
    def popit():
        if len(stack)==0:
            print 'cannot pop from an empty stack!'
        else:
            print 'Removed [', stack.pop(),']'
    
    def viewstack():
        print str(stack)
    
    def showmenu():
        prompt ="""
    
    p(U)sh
    p(o)p
    (v)iew
    (q)uit
    
    Enter choice:"""
        while True:
            while True:
                try:
                    choice=raw_input(prompt).strip()[0].lower()
                except (IndexError, EOFError, KeyboardInterrupt):
                    choice='q'
                print 'nyou picked: [%s]' %choice
                if choice not in 'uovq':
                    print 'invalid option, try again'
                else:
                    break
    
            if choice == 'q': break
            if choice =='u': pushit()
            if choice =='o': popit()
            if choice =='v': viewstack()
    
    if __name__=='__main__':
        showmenu()
    View Code
  • 相关阅读:
    C#连接数据库的三种方法
    远程控制mysql出现的问题
    DFS_子集
    DFS_全排列
    Centos下搭建Mysql
    Nginx与PHP(FastCGI)的安装、配置与优化
    Centos下主DNS的搭建
    Nginx的基本配置与优化
    Nginx服务器的安装与配置
    gdb基本命令
  • 原文地址:https://www.cnblogs.com/augustyang/p/6826816.html
Copyright © 2011-2022 走看看