小白粗试
编译环境:Python 3.5.3
内容:允许脚本用户进行三次尝试
#date:2017年8月25日20:25:28
max_attempts=3
the_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后,自动跳出脚本
正确效果:
输入一次正确结果后自动跳出脚本