Loading subject…
Python, broken:
Python, fixed:
Java, fixed:
Python, tax charged on the pre-discount price:
Python, discount first:
Java, discount first:
Python, never terminates:
Python, fixed by moving one line inside the loop:
Java, fixed:
scores = [72, 65, 88]
for s in scores: total = total + s # NameError: total does not exist yettotal = 0
print(total / len(scores))scores = [72, 65, 88]total = 0
for s in scores: total = total + s
print(total / len(scores)) # 75.0int[] scores = {72, 65, 88};int total = 0;
for (int i = 0; i < scores.length; i++) { total = total + scores[i];}
System.out.println((double) total / scores.length); // 75.0subtotal = 40.00tax = subtotal * 0.08 # tax on 40.00 = 3.20subtotal = subtotal - 5.00 # discount applied too late
print(subtotal + tax) # 38.20subtotal = 40.00subtotal = subtotal - 5.00 # discount firsttax = subtotal * 0.08 # tax on 35.00 = 2.80
print(subtotal + tax) # 37.80double subtotal = 40.00;subtotal = subtotal - 5.00;double tax = subtotal * 0.08;
System.out.println(subtotal + tax); // 37.8count = 0
while count < 5: print(count)count = count + 1 # outside the loop, so it never runscount = 0
while count < 5: print(count) count = count + 1int count = 0;
while (count < 5) { System.out.println(count); count++;}