展开全部
import random
def guess(player):
declare = 'You enter number not between 1 and 99!'
number = int(raw_input('Player %s - Enter a number between 1 and 99:' % player))
if number < 1:
print declare
elif number > 99:
print declare
else:
pass
return number
def game():
i = 1
count = [0,0,0]
falg = True
rambom_num = random.randrange(1,99)
while falg:
for player in range(0,3):
number = guess(player + 1)
count[player] = i
if number > rambom_num:
print 'Your guess is too high!'
elif number < rambom_num:
print 'Your guess is too low!'
else:
print '--------------------------------------'
print 'Your made the right guess!'
print 'The secret number is %s' % number
for p in range(0,len(count)):
print 'Player %s - Total number of guesses: %s' % (p + 1,count[p])
falg = False
break
i = i + 1
game()
>>>
Player 1 - Enter a number between 1 and 99:50
Your guess is too high!
Player 2 - Enter a number between 1 and 99:40
Your guess is too high!
Player 3 - Enter a number between 1 and 99:30
Your guess is too high!
Player 1 - Enter a number between 1 and 99:22
Your guess is too high!
Player 2 - Enter a number between 1 and 99:18
Your guess is too high!
Player 3 - Enter a number between 1 and 99:11
Your guess is too high!
Player 1 - Enter a number between 1 and 99:9
Your guess is too high!
Player 2 - Enter a number between 1 and 99:5
Your guess is too low!
Player 3 - Enter a number between 1 and 99:6
Your guess is too low!
Player 1 - Enter a number between 1 and 99:7
Your guess is too low!
Player 2 - Enter a number between 1 and 99:8
--------------------------------------
Your made the right guess!
The secret number is 8
Player 1 - Total number of guesses: 4
Player 2 - Total number of guesses: 4
Player 3 - Total number of guesses: 3
展开全部
import random
num = int(100*random.random())
print num
player = 0
player1 = 0
player2 = 0
player3 = 0
def inputnum():
global player,player1,player2,player3
player += 1
print player
if player%3 == 1:
value = raw_input('Player 1:')
player1 += 1
elif player%3 == 2:
value = raw_input('Player 2:')
player2 += 1
elif player%3 == 0:
value = raw_input('Player 3:')
player3 += 1
else:
pass
return int(value)
while True:
value = inputnum()
if value == num:
print 'You are True!'
break
elif value > num:
print 'Too High!'
else:
print 'Too Low!'
print 'The secret number is %d'%num
print 'Player 1 guess times:%d'%player1
print 'Player 2 guess times:%d'%player2
print 'Player 3 guess times:%d'%player3
num = int(100*random.random())
print num
player = 0
player1 = 0
player2 = 0
player3 = 0
def inputnum():
global player,player1,player2,player3
player += 1
print player
if player%3 == 1:
value = raw_input('Player 1:')
player1 += 1
elif player%3 == 2:
value = raw_input('Player 2:')
player2 += 1
elif player%3 == 0:
value = raw_input('Player 3:')
player3 += 1
else:
pass
return int(value)
while True:
value = inputnum()
if value == num:
print 'You are True!'
break
elif value > num:
print 'Too High!'
else:
print 'Too Low!'
print 'The secret number is %d'%num
print 'Player 1 guess times:%d'%player1
print 'Player 2 guess times:%d'%player2
print 'Player 3 guess times:%d'%player3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询