代码正在打印原始起始余额5000而不是功能中的修改余额4900。
def Building(mon, house, office):
print("A house costs 100 dollars and an office does too")
building_type = input("House or office?: ")
if building_type == "House":
print("You have built your first building, a house!")
mon -= 100
house += 1
elif building_type == "Office":
print("You have constructed an office in your city!")
mon -= 100
office += 1
else:
print("Neither house or office was entered, enter again.")
Building(mon, house, office)
Building(money, houses, offices)
print(money)
答案 0 :(得分:0)
你应该返回变量mon。
if building_type=="House":
# do calculations
return (mon, house, office)
elif building_type=="Office":
# do calculations
return (mon, house, office)
然后
results = Building(money, house, office)
print(results[0]) # for money
print(results[1]) # for house
print(results[2]) # for office