8-2用python创建随机数游戏
引入random数据库构建新函数guess并设计猜数游戏的最大值为100次数为循环五次控制游戏者的输入范围为1-100否则显示outof range并结束游戏。每次猜数后会显示猜大或者猜小游戏者根据此提示进行下一次的猜测。一旦猜对会显示出congratulations并结束游戏若到最后也未猜对系统显示out并告知答案。fromrandomimportrandintdefguess(maxvalue100,maxtime5):valuerandint(1,maxvalue)foriinrange(maxtime):promptstart to guess:ifi0elseguess again:xint(input(prompt))ifx100orx1:print(out of range)breakifxvalue:print(congratulations)breakelifxvalue:print(high)else:print(low)else:print(out)print(value is,value)guess()