描述:A输入一个数值,输入时该数值已隐藏无法看到,让B猜该数字为多少,数值过小或过大都会提示,并会在最后猜对时统计出共猜了几次。
脚本内容:
#!/usr/bin/env python
#FileName:while1.py
import getpass #调用模块
a = int(getpass.getpass(‘Enter A Number a:‘)) #模块赋值
running = True
i = 0
while running:
b = int(raw_input(‘Enter A number b: ‘))
if a == b:
print ‘\033[32mgood,Your Password is Ture !\033[0m‘
running = False
i = i+1
elif a < b:
print ‘Bad,Pleas Try Again! Is Too Greate!‘
i = i+1
else:
print ‘Bad,Pleas Try Again! Is Too Little!‘
i = i+1
else:
print ‘\033[36mWhat a clever boy !\033[0m‘
if i == 1:
print ‘\033[36mYou used %s chance to give the answer. \033[0m‘ % i
else:
print ‘\033[36mYou used %s chances to give the answer. \033[0m‘ % i
本文出自 “L.P.F” 博客,请务必保留此出处http://liupengfang1015.blog.51cto.com/6627801/1742776
【python笔记 三 】python脚本实战---数字密码小游戏
原文地址:http://liupengfang1015.blog.51cto.com/6627801/1742776