练习
识别三次
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/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')
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/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 'n\you 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()
posted on 2017-05-08 19:10 augustyang 阅读(157) 评论(0) 编辑 收藏 举报