176k views
7 votes
What is wrong with the following code?

numl = int (input("Enter a number: "))
numz = int (input("Enter a number: "D)
num3 = int (input("Enter a number: "))
print ("The average is: + (numl + num2 + num3/3)
The last line should be print ("The average is: (numl + num2 + num/3)
The variables should be lnum, 2num, Bnum
It needs a into command
It needs a stro command

User Vakus
by
6.0k points

1 Answer

2 votes

Code:

numl = int (input("Enter a number: "))

num2 = int (input("Enter a number: "))

num3 = int (input("Enter a number: "))

print ("The average is:" + ((numl + num2 + num3)/3))

Answer:

It needs a str command

Step-by-step explanation:

Given

The above code

Required

Determine and correct the error

At the last line of the code, there is an attempt to print the average of the three numbers.

However, this will return an error because:

In order to print the literal "The average is:" and the numeric value of (numl + num2 + num3)/3, a str command is needed.

This converts (numl + num2 + num3)/3 to a literal and then print without error.

So, the correct instruction is:

print ("The average is:" + str((numl + num2 + num3)/3))

User Manish Doshi
by
4.9k points