Python 我在语法上犯了什么错误?

Python 我在语法上犯了什么错误?,python,Python,我是python新手,必须编写一个代码来计算工资/你做了什么类型的工作(兼职、加班等) 我的代码是: hours=int(input("How many hours did you work?")) rate=int(input("What is your hourly rate?")) bonusr=int(input("What is your bonus rate?")) normaltotal=rate*hours bonus=

我是python新手,必须编写一个代码来计算工资/你做了什么类型的工作(兼职、加班等) 我的代码是:

hours=int(input("How many hours did you work?"))
rate=int(input("What is your hourly rate?"))
bonusr=int(input("What is your bonus rate?"))
normaltotal=rate*hours
bonus=rate*bonusr*(hours-40)
pay+bonus=normaltotal+bonus 
if hours<32:
  print("You worked part-time")
  print(normaltotal)
elif hours>32 and <=40:
  print("You worked Full-Time")
  print(normaltotal)
elif hours>40:
  print("You worked over-time")
  print(pay+bonus)
hours=int(输入(“您工作了多少小时?”)
rate=int(输入(“您的小时费率是多少?”)
bonusr=int(输入(“您的奖金率是多少?”)
正常总计=费率*小时
奖金=费率*奖金*(小时-40)
工资+奖金=正常总额+奖金
如果是32和40小时:
打印(“您随着时间工作”)
打印(工资+奖金)

当您使用'and'逻辑时,我发现“elif hours>32和的语法错误,它将分别操作子句。要正确使用它,您需要声明'hours'两次:

hours=int(input("How many hours did you work?"))
rate=int(input("What is your hourly rate?"))
bonusr=int(input("What is your bonus rate?"))
normaltotal=rate*hours
bonus=rate*bonusr*(hours-40) if hours > 40 else 0
pay_plus_bonus=normaltotal+bonus 
if hours<32:
  print("You worked part-time")
  print(normaltotal)
elif hours>32 and hours<=40:
  print("You worked Full-Time")
  print(normaltotal)
elif hours>40:
  print("You worked over-time")
  print(pay_plus_bonus)
hours=int(输入(“您工作了多少小时?”)
rate=int(输入(“您的小时费率是多少?”)
bonusr=int(输入(“您的奖金率是多少?”)
正常总计=费率*小时
奖金=费率*奖金*(小时数-40),如果小时数>40,则为0
支付+奖金=正常总额+奖金
如果是32小时和40小时:
打印(“您随着时间工作”)
打印(工资加奖金)

pay+bonus=normaltotal+bonus?或
bonus=rate*bonusr*(hours-40)
当我们不知道小时数是否大于40时,有任何问题吗?抱歉,我昨天错过了。你不能在变量名中使用“+”,你需要确保小时数大于40,否则奖金将为负值。请查看我编辑的答案。