Reputation: 5
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
This is my line of code, but under else clothes_total1 > 200:
, I keep getting:
invalid syntax error
Don't know what the problem is. Can someone help me out help? Thank you.
Upvotes: 0
Views: 557
Reputation: 250951
It should be elif
not else
:
elif clothes_total1 > 200:
From docs:
if_stmt ::= "if" expression ":" suite
( "elif" expression ":" suite )*
["else" ":" suite]
And instead of using tot1 + tot2 + tot3 + tot4+ tot5
, I think you should use a list.
Example:
tot = [12,56,....] #some values
and then use sum
:
clothes_total = sum(tot)
If the list has more than 5 items and you want sum of just first 5 items then use slicing:
clothes_total = sum(tot[:5])
Upvotes: 2
Reputation:
else doesn't take a condition, but elif does. If you use else, that means, if EVERYTHING fails, do this.
Upvotes: 0
Reputation: 369064
else
cannot have predicate.
Use elif
instead of else
.
elif clothes_total1 > 200:
Upvotes: 1
Reputation: 1299
else
should be equal to elif
.
This is because in Python, else
acts as a kind of "catch-all"—it doesn't require any additional requirements, and in fact doesn't allow them. If you want to specify conditions for an else clause, then you have to use elif
.
Upvotes: 0