马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 子沙 于 2018-7-28 17:13 编辑 import random
secret=random.randrange(1,101)
print('The integer is between 1 and 100.')
times=int(input('How many times do you want to guess?\n'))
guess=int(input('Enter a integer:'))
i=1
while i<times:
if guess==secret:
if i==1:
print('You only use',i,'chance.')
else:
print('You only use',i,'chances.')
i=times
else:
if guess<secret:
print('No, it is a little higher than that.(',i,'/',times,')')
else:
print('No, it is a little lower than that.(',i,'/',times,')')
guess=int(input('Enter a integer:'))
i=i+1
if guess==secret:
print('Congratulations, you guessed it.')
print('Game is over.')
else:
print('Sorry, you fail the game.(',i,'/',times,')')
print('Game is over. Thanks')
|