# operator-keyword - 试图将变量分配给值会导致"Cannot assign to operator" 错误

``````
def main():
bonus()
def bonus():
#Dollars from sales are input, then time worked,
#then the salary and possible bonus is added
#to the calculated commission based on the earned commission rate
monthlySales=int(input('How much money did your employee make in sales?',))
if monthlySales<10000:
commRate=0
elif monthlySales>=10000 and monthlySales<100000:
commRate=0.02
elif monthlySales>=100001 and monthlySales<500000:
commRate=0.15 and monthlyBonus=1000
elif monthlySales>=500001 and monthlySales<1000000:
commRate=0.28 and monthlyBonus=5000
elif monthlySales>1000000:
commRate=0.35 and monthlyBonus=100000
yearsWorked=int(input('How many years has your employee worked here? Round down to the nearest year.',))
if yearsWorked>=5 and monthlySales>=100000:
extraBonus+1000
elif yearsWorked<1:
monthsWorked=int(input('How many full months has your employee worked here?',))
if monthsWorked<3:
print('Your employee has not worked here long enough to qualify for a bonus.')
main()

``````

``````
commRate=0.35 and monthlyBonus=100000

``````

``````
elif monthlySales>=100001 and monthlySales<500000:
commRate=0.35 ; monthlyBonus=100000

``````

``````
elif monthlySales>=100001 and monthlySales<500000:
commRate=0.35
monthlyBonus=100000

``````

``````
elif monthlySales>=100001 and monthlySales<500000:
commRate=0.15
monthlyBonus=1000
elif monthlySales>=500001 and monthlySales<1000000:
commRate=0.28
monthlyBonus=5000
elif monthlySales>1000000:
commRate=0.35
monthlyBonus=100000

``````

https://docs.python.org/2/tutorial/datastructures.html

`extraBonus+1000` 对未定义的变量( extraBonus ) 执行计算，然后将结果存储在任何位置。

``````
monthlyBonus = 0
if monthlySales <10000:
commRate = 0
elif monthlySales <100000:
commRate = 0.02
elif monthlySales <500000:
commRate = 0.15; monthlyBonus = 1000
elif monthlySales <1000000:
commRate = 0.28; monthlyBonus = 5000
else:
commRate = 0.35; monthlyBonus = 100000

``````