今天享学课堂给大家介绍一下关于零基础学习python视频教程之猜数字游戏代码片段的介绍,下面我们一起来看一下吧!
?[代码]猜数字游戏,有次数限制并且打分
importrandom
num=random.randint(0,100)
times=0
print"Number(0,100)guessgame"
print"Youwillhave10timestoguess"
print"Guessoutofrangewillgameoverimmediately!"
guess=int(raw_input("guessanumber:"))
times=times+1
while0
iftimes==10:
ifguess>num:
print"Toohigh,Thenumberis",num
print"Guesstimesover,gameover!"
elifguess
print"TooLow,Thenumberis",num
print"Guesstimesover,gameover!"
else:
print"Youguessit.Thenumberis:",num
score=10*(11-times)
print"timesis:",times
print"Yourscoreis",score
break
else:
ifguess>num:
print"Toohigh,guessagain!"
elifguess
print"TooLow,guessagain!"
else:
print"Youguessit.Thenumberis:",num
score=10*(11-times)
print"timesis:",times
print"Yourscoreis",score
break
guess=int(raw_input("guessanumber:"))
times=times+1
else:
print"Yourguessisoutofrange!Gameover!"
领取专属 10元无门槛券
私享最新 技术干货