2013-07-18 76 views
-4
def main(): 
    import time 
    import random 
    def basic(): 
    nl = "-----------------------Loading Please Wait--------------------" 

    print (nl) 
    print("wellcome to trade seas") 
    print (nl) 
    namE = raw_input("What is your name caption\n") 
    nameS = namE + "'s" 
    cap = "Caption " 
    tion = " info" 
    gold2 = str(500) 
    gold1 = "\ngold --------- $" 
    sails1 = "\nSails left ---" 
    sails2 = 10 
    print (nl) 
    iL = ("\n~~~Caption here is our map~~~\nPort Royal --- 'a'\nFlorida Keys --- 'b'\nHavana --- 'c'") 
    aportroyal = "a" 
    bfloridakeys= "b" 
    bhavana = "c" 
    foodshoP = "b1" 
    shipyarD = "b2" 
    sailL = "b3" 
    buildingL = ("\nFood Shop ---- b1\nShipYard\n") 
    apples = 3 
    bananas = 5 
    foodlisT = ("\napples ---- f1\nbanana ---- f2") 
    info = cap + str(nameS) + tion + gold1 + str(gold2) + sails1 + str(sails2) 
    global info 
    global gold2 
    def Start(): 
        global info 
        print (info) 

        print (iL) 
        print (nl) 
        sails = raw_input("What island would you like to sail to caption?\n") 
        taX = random.randint(30, 50) 


        global gold2 

        if aportroyal == sails: 


         print (nl) 
         print ("import tax of $", + taX,"\nWellcome to Port Royal") 
         ranG = random.randint(3, 4) 

         gold2 -= taX 

         info1 = cap + str(nameS) + tion + gold1 + str(gold2) + sails1 + str(sails2) 
         print(info1) 
        elif bfloridakeys == sails: 

         taX = random.randint(20, 38) 
         info = cap + str(nameS) + tion + gold1 + str(gold2) + sails1 + str(sails2) 
         print (info1) 
         gold2 -= taX 
         print (nl) 
         print ("import tax of $", + taX,"\nWellcome to Florida Keys") 
         ranG = random.randint(2, 3) 

        elif bhavana == sails: 

         taX = random.randint(2, 20) 
         gold2 -= taX 
         info = cap + str(nameS) + tion + gold1 + str(gold2) + sails1 + str(sails2) 
         print (info1) 
         print (nl) 
         print ("import tax of $", + taX,"\nWellcome to Florida Keys") 
         ranG = random.randint(1, 2) 

        else: 
        print (nl) 
        def prices(): 
        bapples2 = apples * ranG 
        bapples1 = "bf1---apples ------ $" 
        bbananas2 = bananas * ranG 
        bbananas1 = "\nbf2---bananas ------ $" 
        sbananas2 = bananas/ranG 
        sbananas1 = "sf2-------banana ------ $" 
        sapples2 = apples/ranG 
        sapples1 ="\nsf1 ----apples ------ $" 
        buypL = bapples1 + str(bapples2) + bbananas1 + str(bbananas2) 
        bf1 = "bf1" 
        bf2 = "bf2" 

        def port(): 
         print (buildingL) 
         print (nl) 
         buildinG = raw_input("what building would you like to go in caption\n") 

         if foodshoP == buildinG: 
          print ("wellcome to the food shop") 
          buysell = raw_input("hi catption 'buy' or 'sell'?\n") 
          buY = "buy" 
          selL = "sell" 
          gold2 = gold2 
          if buY == buysell: 
          print (buypL)        
          bbuy = raw_input("type food name to buy, or type anykey to return") 
          if bf1 == bbuy: 

          gold2 -= bapples 
          print (info2) 
          return port() 
          else: 
          return port() 
          else: 
          return port() 


         else: 
          return port() 


        port() 
        prices() 
    Start() 
    basic() 
main() 

我的錯誤就行52爲什麼我得到這個錯誤「不支持的操作數類型」?

Unsupported operand type for -= str and int 
+2

哪一行是52? – svineet

+0

信息的哪部分你不明白? – SLaks

回答

3

你給gold2一個字符串值:

gold2 = str(500) 

但儘量以整數減去:

gold2 -= taX 

不要這樣做:

>>> gold2 = str(500) 
>>> gold2 -= 30 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: unsupported operand type(s) for -=: 'str' and 'int' 

也許你的意思是讓gold2是一個整數?

+0

爲什麼gold2會分配一個字符串?當他印刷時,如果我正確地閱讀,他會再次投下它? info =(...)+ str(gold2)+(...); – Kheldar

+0

@Kheldar:確切地說。 –

相關問題