最后一次假如不够10元的话就会出问题,还有判断money应该大于0,不是大于等于。下面代码可用
money = 100i = 0while money <=100 and money > 0: a = random.randint(1,10) if money < 10: a = random.randint(1,money) money = money - a i = i + 1 print "第%s个人,收到%s元,还剩%s元" %(i,a,money)