【发布时间】:2014-04-11 02:09:49
【问题描述】:
第二个左括号在标识符中返回无效字符。该程序预计会打印出员工的月薪。我检查了我的缩进,它看起来很好,并在这里和那里删除了括号来替换。
#Input hoursWorked
#Input hourPay
#Ask “Consultancy income? (Leave blank if none)”
# If value:
# Input consultFee
# monthlySalary = ((hourPay - (hourPay * 0.1)) * hoursWorked) + (consultFee – (consultFee * 0.2))
# Elif no value:
# monthlySalary = hoursWorked * hourPay
#print (“The monthly wage is $”,monthlySalary)
hoursWorked = input ("Hours worked: ")
hourPay = input ("Hour pay: $")
consultFee = input ("Consultant fee? (Leave blank if none): $")
if consultFee is '':
monthlySalary = hourPay * 0.1
elif consultFee is not '':
monthlySalary = ((hourPay - (hourPay * 0.1)) * hoursWorked) + (consultFee – (consultFee * 0.2))
print ("The monthly salary is: $",(int(monthlySalary)))
【问题讨论】:
-
顺便说一句,使用
==来测试等效性 (e.g. consultFree == '') 而不是is。is测试身份,所以'' is not False但'' == False -
第二个左括号哎呀:(consultFee – ( ConsultFee * 0.2))
-
@AdamSmith 我在实现后将输入更改为 int(input("Hurr")) ,但这仍然对标识符中的无效字符没有帮助:/
-
我重新输入了monthlySalary 行,错误消失了。
-
你的文本编辑器是什么?它可能会将
-转换为 m-dashes。
标签: python formula identifier