python之验证用户输入

来源:互联网 发布:软件开发 外包 杭州 编辑:程序博客网 时间:2024/05/01 04:50

小白粗试

      编译环境:Python 3.5.3 内容:允许脚本用户进行三次尝试
#date:2017年8月25日20:25:28max_attempts=3the_word='gululu'#########  get  input word  #########print()for attempt_number in range (1,max_attempts+1):      secret_word=input("What is the secret word! ")      if secret_word == the_word:        print()        print("good!you know the secret word!")        print()        break      #stop the getting word      else:        print()        print("That is wrong word! ")        print("You have",max_attempts-attempt_number,"attempts left.")        print()    

错误效果:
输入3次错误word后,自动跳出脚本

这里写图片描述

正确效果:
输入一次正确结果后自动跳出脚本
这里写图片描述

原创粉丝点击