如下,在主函数中输入数值计算税收,后在函数中加入全局变量,对 my_price 重新赋值
为什么图中两行代码换了一个位置,输出结果会不一样?既然已经全局变量了,不应该都是输出10000吗
菜鸟求助大神,感谢
def calculateTax(price,tax_rate):
total=price+(price*tax_rate)
return total
global my_price
my_price=10000
my_price = float(input("enter a price:"))
totalPrice = calculateTax(my_price,0.06)
print("price= ",my_price,"Total price=",totalPrice)