Skip to main content
 首页 » 编程设计

Python3之标识符中的无效字符(公式内)

2025年05月04日8虾米哥

第二个左括号返回标识符中的无效字符。该程序预期打印出员工的月薪。我检查了我的缩进,它看起来很好,并删除了这里和那里的括号以替换。

#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))) 

请您参考如下方法:

您在该位置使用的减号不是常规减号(连字符-减号),而是短划线。在同一行的前面,您有一个常规减号。奇怪的是,您将两者都放在同一个文件中。您需要使用面向编程或至少面向纯无格式文本的文本编辑器。