2013-07-28 124 views
0
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 clothes_total1 > 200:下,我不斷收到:無效的Python語法錯誤(2.7.5)

無效的語法錯誤

不知道是什麼問題是。有人可以幫助我嗎?謝謝。

+0

它的工作原理!非常感謝! – James

回答

0

else應該等於elif

這是因爲在Python中,else充當一種「全能」—它不需要任何額外的要求,並且實際上不允許它們。如果你想爲else子句指定條件,那麼你必須使用elif

+0

Python沒有'else if'。 – falsetru

+0

@falsetru哈哈,我知道,錯字。固定。爲什麼downvote? – tehsockz

2

else不能有謂詞。使用elif而不是else

elif clothes_total1 > 200: 
3

應該elifelse

elif clothes_total1 > 200: 

docs

if_stmt ::= "if" expression ":" suite 
      ("elif" expression ":" suite)* 
      ["else" ":" suite] 

而不是使用tot1 + tot2 + tot3 + tot4+ tot5,我認爲你應該使用的列表。

例子:

tot = [12,56,....] #some values 

然後用sum

clothes_total = sum(tot) 

如果列表中有超過5個項目,你想的只是第5項之和,然後用切片:

clothes_total = sum(tot[:5]) 
0

否則不接受條件,但e lif的確如此。 如果您使用其他方式,則意味着如果一切都失敗,請執行此操作。