-5
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
4

1 回答 1

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一个整数?

于 2013-07-18T13:38:44.940 回答