1 def discounts(price, rate):
2 final_price = price * rate
3 old_price = 88 #这里试图修改全局变量
4 print('修改后old_price的值是:', old_price)
5 return final_price
6
7 old_price = float(input('请输入原价:'))
8 rate = float(input('请输入折扣率:'))
9 new_price = discounts(old_price, rate)
10 print('修改后old_price的值是:', old_price)
11 print('打折后价格是:', new_price)
global可将局部变量声明为全局变量