我的Elif陈述出现语法错误

时间:2019-06-18 03:24:46

标签: python-3.x

嗨,大家好,当我尝试运行我的程序时,它会弹出一个框,提示语法无效,然后使Elif变成红色

sales_amount = int(input('what is your sales amount to your commission rate 
Example: 5000$ to 2%'))
goal_salary = int(input('what is your goal salary'))
commission_rate = float(input('what is your commissioin rate to your sales 
amount Example: 5000$ to 2%  P.S. please write as decimal'))

final_sales_amount=sales_amount
final_commission_rate=commission_rate
the_number=1
commission=0
sales=0.01

while sales_amount*commission_rate==goal_salary:
    print('your sales amount is', sales)
    print('your commission rate is', commission) 
    break
elif the_number*sales_amount==0.01:
    the_number+1
    commission+commission_rate
else:
    sales=sales+0.01

1 个答案:

答案 0 :(得分:0)

如果第一个elif与cond不匹配,则使用if。 例如:

a = 1
if a ==2:
 print('lol')
elif a == 1:
 print('wow')

在此示例中,输出为wow,但是如果if中的cond为True,则不会检测到elif(或不进行elif代码)。

如果在任何Else中没有cond并且if为True,则使用

elif。 例如:

a = 3
if a == 1 or a ==5:
 print('1/5')
elif a == 2 or a == 4:
 print('2/4')
else:
 print('i have nothing')

,输出将为i have nothing,因为a == 1 or a ==5不正确,a ==2 or a == 4也不正确,因此,其他情况,else: print('i have nothing')是命令解决方案的方法