码迷,mamicode.com
首页 > 编程语言 > 详细

python编程快速上手之第10章实践项目参考答案(10.8)

时间:2017-04-23 15:02:52      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:color   really   cti   logs   rand   内容   while   oss   dom   

 1 #通过DEBUG可以看出是guess输入内容(heads, tails)和TOSS内容(0,1)不一致,需修改和TOSS的比较项。
 2 import random,logging
 3 logging.basicConfig(level=logging.DEBUG, format=%(asctime)s - %(levelname)s - %(message)s)
 4 logging.debug(Start of program)
 5 guess = ‘‘
 6 n=‘‘                                         #新增一个函数n
 7 while guess not in (heads, tails):
 8   print(Guess the coin toss! Enter heads or tails:)
 9   guess = input()
10   logging.debug(inputwords:(%s%%) % (guess))#debug guess内容
11   if guess == (heads):
12     n = 1
13   elif guess == (tails):
14     n = 0
15   logging.debug(inputwords:(%s%%) % (n))#debug n 内容
16 toss = random.randint(0, 1) # 0 is tails, 1 is heads
17 logging.debug(toss:(%s%%) % (toss))  #debug toss 内容
18 if toss == n:
19   print(You got it!)
20 else:
21   print(Nope! Guess again!)
22   guesss = input()
23   if toss == n:
24     print(You got it!)
25   else:
26     print(Nope. You are really bad at this game.)

 

python编程快速上手之第10章实践项目参考答案(10.8)

标签:color   really   cti   logs   rand   内容   while   oss   dom   

原文地址:http://www.cnblogs.com/flying-wyf/p/6752478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!