数学方程出错

时间:2016-10-10 18:35:07

标签: python

我的问题是,如果你看'支持'变量。 (在变量列表中)它不适用于当前消耗。对于EX。如果我按'S'并进入开始游戏,然后按'M'显示任务,然后按'S'选择幸存者任务。我收到了2名幸存者。由于某种原因,这个数字不会增加支持并显示“你正在消耗0.5等等等等”而不是“你消耗0.7等等等等等等”,因为它应该为每个人增加0.1?对不起,如果这很难理解,我只想尝试编程!     随机导入     来自PIL导入图像

print('\x1b[6;30;42m' + 'Zombie Survival Simulator' + '\x1b[0m')
print "Press [S] to start!"
resp = raw_input()
if 's' in resp or 'S' in resp:
    foodmission = ['Convience Store','Grocery Store','Restraunt','Food Storage Area']
    watermission = ['Convience Store', 'Old Gas Station', 'Water Tower','Toppled Coca-Cola truck.']
    survivormission = ['Abandoned Refugee Camp','Bus','Army Camp','Train Station']
    "FOOD"
    #Pick Area
    def pickfoodMission():
        foodmis = random.choice(foodmission)
        return foodmis
    #Chance to get food
    def chanceFood():
        foodcha = random.randint(1,20)
        return foodcha
    #How much food you gain a mission
    def foodPickup():
        foodpick = random.randint(1,2)
        return foodpick
    "WATER"
    #Pick the area
    def pickwaterMission():
        watermis = random.choice(watermission)
        return watermis
    #Chance for getting water
    def chancewater():
        watercha = random.randint(1,20)
        return watercha
    #Number of water you gain a mission
    def waterPickup():
        waterpick = random.randint(1,2)
        return waterpick
    "SURVIVORS"
    #Pick the area
    def picksurvivorMission():
        survivormis = random.choice(survivormission)
        return survivormis
    #Chance for getting water
    def chancehuman():
        humancha = random.randint(1,20)
        return humancha
    #Number of water you gain a mission
    def humanPickup():
        humanpick = random.randint(1,2)
        return humanpick


    food = 3
    water = 3
    human = 5
    healthy = 0
    con = 0.1
    level = 1
    game = 1
    new = 1
    foodcon = 0
    watercon = 0
    support = 0.1 * human
    newhuman = (human + (1 + (human / 5)) + healthy)
    newwater = (water + (1 + (human / 5)) + healthy)
    newfood = (water + (1 + (human / 5)) + healthy)
    while game == 1:
        if food <= 0 or water <= 0:
            print('\x1b[7;30;41m' + 'You and your friends are dead.' + '\33[3m')
            break
        if food >= 3 or water >= 3:
            healthy = healthy + 1
        if food <= 2 or water <= 2:
            healthy = healthy - 1
        print "Current Resources: Food: " +str(food) + " Day(s) Water: " + str(water) + " Day(s)"
        print "Current Survivors " + str(human)
        if healthy <= -3 and healthy >= -1:
            print "Current Survivors are " + ('\x1b[7;30;41m' + 'Nearly Dead' + '\33[3m')
        if healthy == 0:
            print "Current survivors " + ('\x1b[7;30;41m' + 'Are not healthy' + '\33[3m')
        if healthy >= 1 and healthy <= 3:
            print "Current Survivors are " + ('\x1b[7;32;43m' + 'Ok' + '\x1b[0m')
        if healthy >= 3 and healthy <= 5:
            print "Current Survivors are " + ('\x1b[7;32;43m' + 'Great' + '\x1b[0m')
        if healthy >= 5 and healthy <= 7:
            print "Current Survivors are " + ('\x1b[7;32;43m' + 'Excellent' + '\x1b[0m')
        foodcon = support
        watercon = support
        food = food - support
        water = water - support
        print human
        print support
        print "You are consuming " + str(support) + " food and " + str(support) + " water per day"
        if food - support <= 0 or water - support <= 0:
            print('\x1b[7;30;41m' + 'You will not survive the next day.' + '\33[3m')
        print "[M]issions [B]uilding [H]oard [E]nd Day"
        resp = raw_input()
        if 'M' in resp or 'm' in resp:
            print "[F]ood [W]ater [S]urvivor"
            resp = raw_input()
            if 'F' in resp or 'f' in resp:
                foodmis = pickfoodMission()
                print "You go to a " + foodmis
                foodcha = chanceFood()
                if foodcha >= 14:
                    foodpick = foodPickup()
                    food = newfood
                    img = Image.open('food.png')
                    img.show()
                    print('\x1b[7;32;43m' + 'You are now at ' + str(newfood) + ' day(s) of food' + '\x1b[0m')
                elif foodcha < 14:
                    print('\x1b[7;30;41m' + 'You come back empty handed.' + '\x1b[0m')
            elif 'w' in resp or 'W' in resp:
                watermis = pickwaterMission()
                print "You go to a " + watermis
                watercha = chancewater()
                if watercha >= 14:
                    waterpick = waterPickup()
                    water = newwater
                    img = Image.open('water.png')
                    img.show()
                    print('\x1b[7;32;43m' + 'You are now at ' + str(newwater) + ' day(s) of water' + '\x1b[0m')
                elif watercha <= 14:
                    print('\x1b[7;30;41m' + 'You come back empty handed.' + '\x1b[0m')
            elif 's' in resp or 'S' in resp:
               humanmis = picksurvivorMission()
               print "You go to a " + humanmis
               humancha = chancehuman()
               if humancha >= 14:
                    humanpick = humanPickup()
                    human = newhuman
                    print('\x1b[7;32;43m' + 'You are now at ' + str(human) + ' survivor(s)' + '\x1b[0m')
                    img = Image.open('cats.jpg')
                    img.show()
               elif humancha <= 14:
                    print('\x1b[7;30;41m' + 'You come back with no one else new.' + '\x1b[0m')
        if 'B' in resp or 'b' in resp:
            print "[F]ood"

2 个答案:

答案 0 :(得分:1)

第一次设置后,您永远不会更新support变量,因此每次打印它都是相同的。由于support取决于human,因此您应该在每次更新support时重新计算human,或者使用calculate_support()这样的函数在需要时计算'$$$'

答案 1 :(得分:0)

据我所见,您只需快速浏览一下,您只需为“支持”指定价值。代码中的变量一次:

support = 0.1 * human

我并不认为此代码会再次运行。一旦支持通过此赋值语句获得值,即使您更新了&#39; human&#39;的值,它也不会更新。变量。