Python无效语法错误(2.7.5) 服装总计=总计1+总计2+总计3+总计4+总计5 衣服总计1=总计1+总计2+总计3+总计4+总计5 总价=税金*(服装总额+运费+礼品编号) 总价格1=税*(衣服总数1*0.85+运费+礼品编号) 总价格2=税*(服装总价格2*0.85+运输+礼品编号-30) 打印“原价:$%s”%t总计 如果衣服总数200: 打印“15%折扣+30美元折扣:$” 打印0.85*(衣服总数-30件) 打印“三十:$%s”%tot_price 2
这是我的代码行,但在Python无效语法错误(2.7.5) 服装总计=总计1+总计2+总计3+总计4+总计5 衣服总计1=总计1+总计2+总计3+总计4+总计5 总价=税金*(服装总额+运费+礼品编号) 总价格1=税*(衣服总数1*0.85+运费+礼品编号) 总价格2=税*(服装总价格2*0.85+运输+礼品编号-30) 打印“原价:$%s”%t总计 如果衣服总数200: 打印“15%折扣+30美元折扣:$” 打印0.85*(衣服总数-30件) 打印“三十:$%s”%tot_price 2,python,syntax,Python,Syntax,这是我的代码行,但在其他衣服\u total1>200:下,我不断得到: 无效语法错误 我不知道是什么问题。有人能帮帮我吗?谢谢。否则应等于elif 这是因为在Python中,else充当一种“包罗万象”的角色——它不需要任何额外的需求,事实上也不允许它们。如果要为else子句指定条件,则必须使用elifelse应等于elif 这是因为在Python中,else充当一种“包罗万象”的角色——它不需要任何额外的需求,事实上也不允许它们。如果要为else子句指定条件,则必须使用elifelse不能有
其他衣服\u total1>200:
下,我不断得到:
无效语法错误
我不知道是什么问题。有人能帮帮我吗?谢谢。
否则
应等于elif
这是因为在Python中,
else
充当一种“包罗万象”的角色——它不需要任何额外的需求,事实上也不允许它们。如果要为else子句指定条件,则必须使用elif
else
应等于elif
这是因为在Python中,
else
充当一种“包罗万象”的角色——它不需要任何额外的需求,事实上也不允许它们。如果要为else子句指定条件,则必须使用elif
else
不能有谓词
使用elif
而不是else
clothes_total = tot1 + tot2 + tot3 + tot4+ tot5
clothes_total1 = tot1 + tot2 + tot3+ tot4 + tot5
tot_price = tax * (clothes_total + shipping + gift_number)
tot_price1 = tax * (clothes_total1 * 0.85 + shipping + gift_number)
tot_price2 = tax * (clothes_total2 * 0.85 + shipping + gift_number - 30)
print "<h4>Original Price: $ %s </h4>" % clothes_total
if clothes_total < 150:
print "<h4> TOTAL : %s </h4>" % tot_price
else clothes_total1 > 200:
print "15% Discount + $30 off: $"
print 0.85 * (clothes_total - 30)
print "<h4> THIRTY: $ %s </h4>" % tot_price2
else
不能有谓词
使用elif
而不是else
clothes_total = tot1 + tot2 + tot3 + tot4+ tot5
clothes_total1 = tot1 + tot2 + tot3+ tot4 + tot5
tot_price = tax * (clothes_total + shipping + gift_number)
tot_price1 = tax * (clothes_total1 * 0.85 + shipping + gift_number)
tot_price2 = tax * (clothes_total2 * 0.85 + shipping + gift_number - 30)
print "<h4>Original Price: $ %s </h4>" % clothes_total
if clothes_total < 150:
print "<h4> TOTAL : %s </h4>" % tot_price
else clothes_total1 > 200:
print "15% Discount + $30 off: $"
print 0.85 * (clothes_total - 30)
print "<h4> THIRTY: $ %s </h4>" % tot_price2
它应该是
elif
而不是else
:
elif clothes_total1 > 200:
发件人:
我认为你应该使用列表,而不是使用tot1+tot2+tot3+tot4+tot5
示例:
if_stmt ::= "if" expression ":" suite
( "elif" expression ":" suite )*
["else" ":" suite]
然后使用sum
:
tot = [12,56,....] #some values
如果列表中有5个以上的项目,并且您只需要前5个项目的总和,则使用切片:
clothes_total = sum(tot)
它应该是
elif
而不是else
:
elif clothes_total1 > 200:
发件人:
我认为你应该使用列表,而不是使用tot1+tot2+tot3+tot4+tot5
示例:
if_stmt ::= "if" expression ":" suite
( "elif" expression ":" suite )*
["else" ":" suite]
然后使用sum
:
tot = [12,56,....] #some values
如果列表中有5个以上的项目,并且您只需要前5个项目的总和,则使用切片:
clothes_total = sum(tot)
else不具备条件,但elif具备条件。
如果您使用else,这意味着,如果所有操作都失败,请执行此操作。else不接受条件,但elif接受条件。
如果您使用else,这意味着,如果所有操作都失败,请执行此操作。Python没有
else If
。Python没有else If
。它可以工作!非常感谢你!它起作用了!非常感谢你!