79.8k views
4 votes
Read the following code, written to calculate an average:

def main():

num1 = 85

num2 = 95

num3 = 91


average = num1 + num2 + num3 / 3

print("Average: " + str(average))

main()


Which line of code has an error and why? (5 points)


A average = num1 + num2 + num3 / 3; It does not use quotation marks to indicate the string literal.

B average = num1 + num2 + num3 / 3; It does not follow the proper order of operations.

C print("Average: "str(average)); It requires an equal sign to properly calculate the output.

D print("Average: "str(average)); It requires a float() function to properly display the output

User JKupzig
by
4.7k points

1 Answer

2 votes

Answer:

B

Step-by-step explanation:

average = num1 + num2 + num3 / 3 // Divides num3 by 3 then adds num1 and num2

(num1 + num2 + num3) / 3 // Adding brackets adds all three nums first then divides by 3, giving you the average.

User Alexey Volkov
by
5.2k points