The following code has some errors. Write the names of errors/exceptions
which will be raised, underline the error and correct the code
if num>=10:
print("Half of the number is ", "num"/2)
else:
print("The number is ",num)
Answers
Answered by
4
Answer:
error in line number 2
Explanation:
error in line number 2 here you have written :-
print("Half of the number is ", "num"/2)
but at last line here "num" is in from of string and it could not be divided....
Answered by
13
Given code:
if num >= 10:
print("Half of the number is", "num"/2)
else:
print("The number is", num)
Corrected code:
if num >= 10:
print("Half of the number is", num/2)
else:
print("The number is", num)
Correction made:
The assumed data type of num would be an integer. And it was meant to be divided by 2 to obtain its half value. However, in the given code, the variable num was put in quotes, turning it into a string data type, and strings cannot be divided.
Similar questions