2015-04-01 77 views
-1

我想从我的用户得到的输入分配一个'阵营',并根据以下输入修改curAdvRep \ curCrmRep的值。从函数int可变增量

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

从文件2调用文件1:

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 

我很抱歉,如果任我的问题还是我的代码进攻。我已经为我的问题研究了一个答案,但是由于没有找到匹配的答案或者我无法将间接答案翻译成我的具体问题,我还没有找到解决方案。

+0

而不是简单地降评级,请告诉我什么即时做错了...... 我想有我主程序从我的职能分开。 Main =文件1,函数= File2。 Main将收集并存储来自用户的输入并调用函数来传递变量。 基于用户输入,我需要修改来自函数的变量,并让它在文件1和文件2中随后调用该变量时使用。 请帮我理解。 – DaNNuN 2015-04-02 20:23:03

回答

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