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
  • 相关阅读:
    常见错误--06.18
    类目-延展-协议
    iOS页面传值-wang
    ios常见的页面传值方式
    delegate和protocol
    沙盒路径及文件 操作
    tableView优化性能
    IOS面试题
    浅谈Runloop
    面试题
  • 原文地址:https://www.cnblogs.com/augustyang/p/6826816.html
Copyright © 2011-2022 走看看