函数的int变量增量

时间:2015-04-01 02:39:20

标签: function python-3.x

我正在尝试从我的用户那里获得一个'派系的输入。并根据以下输入修改curAdvRep \ curCrmRep的值。

输入显示我得到所需结果的功能,但我需要能够永久修改派系的代表。

从文件1中调用的文件2:

curAdvRep = 0
curCrmRep = 0
Crimson = "Crimson Brootherhood reputation: {0}".format(curCrmRep)
Advent = "Advent of Chaos reputation: {0}".format(curAdvRep)
PathSelDict = {'Advent' : Advent, 'Crimson' : Crimson, 'n' : n, 'c' : cont, 'd' : d, 'p' : p, 'l' : l}

def Faction (rep):
    global curAdvRep
    global curCrmRep
    global Advent
    global Crimson

    if rep in PathSelDict:
        if rep == 'Advent':
            curAdvRep += 50
            curCrmRep -= 5
            Advent = "Advent of Chaos reputation: {0}".format(curAdvRep)
            print(Advent)
            #print(Factions[JoinWorld])
        elif rep == 'Crimson':
            curAdvRep -= 5
            curCrmRep += 50
            print(PathSelDict[JoinWorld])
    else:
        print(Dismiss)
        sys.exit(0)

从文件1:

rep = input("Which side are you on? Advent or Crimson? ").title()
questfunc.Faction(rep)
print(Advent)
print(curAdvRep)
print(curCrmRep)

输出:

 Pick up the box or leave it alone? (p or l): p
Pick up the box
Reputation Gain
Advent of Chaos reputation: 5
Which side are you on? Advent or Crimson? advent
Advent of Chaos reputation: 55
Advent of Chaos reputation: 0
0
0

如果我的问题或我的代码令人反感,我很抱歉。我已经研究了我的问题的答案,但是由于找不到匹配的答案或我无法将间接答案翻译成我的具体问题,我还没有找到解决方案。

1 个答案:

答案 0 :(得分:0)

所以我找到了解决方法。对于那些也提出这个问题并且没有任何有用回复的人,请看一下。

Choice1 = input(" Pick up the box or leave it alone? (p or l): ").lower()
RepGain(Choice1)
print(Advent, curAdvRep)


# Function for gain 
def RepGain (Choice):
    global curAdvRep
    global curCrmRep
    global Advent
    global Crimson

    if Choice in PathSelDict:
        if Choice == 'p':
            print('Reputation Gain\nAdvent + 100')
            curAdvRep += 100
            return curAdvRep
        elif Choice == 'l':
            print('Crimson + 100')
            curCrmRep += 100
            return curCrmRep 
        else:
            print(Dismiss)
            sys.exit(0)

Output:
Reputation Gain
Advent + 100
Advent of Chaos reputation: 100