硬币抛掷:
一个简单的硬币抛掷猜测游戏,玩家有两次猜测机会。
代码如下:
import random
guess = raw_input('Please enter heads or tails:').strip()
toss = {0: 'heads', 1:'tails'}
n = random.randint(0,1)
if toss[n] == guess:
print ('You got it!')
else:
print('Nope! Guess agein!')
guess = raw_input('Please enter heads or tails:').strip()
if toss[n] == guess:
print('You got it!')
else:
print('Nope. You are really bad at this game.')
测试结果:
Please enter heads/tails:heads
Nope! Guess agein!
Please enter heads/tails:tails
You got it!
个人微博:http://weibo.com/wjrtaojiang,各种优惠券走起!!!
5

被折叠的 条评论
为什么被折叠?



