python - Why do I get this error "unsupported operand type"? -
def main(): import time import random def basic(): nl = "-----------------------loading please wait--------------------" print (nl) print("wellcome trade seas") print (nl) name = raw_input("what 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 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 sail caption?\n") tax = random.randint(30, 50) global gold2 if aportroyal == sails: print (nl) print ("import tax of $", + tax,"\nwellcome 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 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 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 go in caption\n") if foodshop == building: print ("wellcome 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 buy, or type anykey return") if bf1 == bbuy: gold2 -= bapples print (info2) return port() else: return port() else: return port() else: return port() port() prices() start() basic() main() i error on line 52
unsupported operand type -= str , int
you gave gold2 string value:
gold2 = str(500) but try subtract in integer:
gold2 -= tax don't that:
>>> gold2 = str(500) >>> gold2 -= 30 traceback (most recent call last): file "<stdin>", line 1, in <module> typeerror: unsupported operand type(s) -=: 'str' , 'int' perhaps meant make gold2 integer instead?
Comments
Post a Comment