python题目:一个小小的猜名有戏


代码逻辑(无图形界面和输入):

# coding:utf-8
from random import randint
global errCount
def pickName():
	nameList = ["ALAN TURING", "DONALD KNUTH", "ADA LOVELACE", "GRACE HOPPER", "GORDON MOORE"]
	return nameList[randint(0, 4)]

def drawMan(errCount):
	if errCount == 1: print "head"
	if errCount == 2: print "body"
	if errCount == 3: print "left hand"
	if errCount == 4: print "right hand"
	if errCount == 5: print "left foot"
	if errCount == 6: print "right foot"

if __name__ == "__main__":
	# name = pickName()
	name = "ALAN TURING"
	lenName = len(name)
	print "pick name:", name
	guessList = [""]*lenName
	print "guessList", guessList
	############### 循环输入输入 #############
	input = "AGIACLDNRUT" 	
	flag = 0
	errCount = 0 
	for inlet in input:
		flag = 1
		for i in range(lenName):		# 开始猜测
			if name[i] in name[:i-1]:	# 检测过的字母跳过
				continue
			if name[i] ==" ":			# 处理空格
				guessList[i] == " "
				blank = i
			if name[i] == inlet:
				guessList[i] == inlet
				flag = 0
		if flag == 1:					# 没有检测到
			errCount += 1
			drawMan(errCount)
	if errCount < 6: 
		print "Congratulations!"
	else: 
		print "You lost! The answer was:\n",name



©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值