Rewrite the code after correcting the errors.
a = int [“Enter a number
for a: ”] for in range (1, 15)
if a = b
print “Equal numbers”
else
print “Non equal numbers”
Answer:
Corrected code:
a = int (input (
"Enter a number for a: "
))
for b in range (
1
,
15
):
if (a==b):
print (
"Equal numbers"
)
else:
print ("Non equal numbers")
Explanation:
- a = int [“Enter a number for a: ”]
Incorrect parentheses and input( ) is missing
- for in range (1, 15)
Control variable ‘b’ is missing and colon (:) at the end of the statement is also missing.
- if a = b
For comparing two variables “==” is used. Here only = is used which is an assignment operator. Parentheses and colon (:) are also missing.
- print “Equal numbers”
Parentheses are missing. print( ) is a method and hence should have opening and closing parentheses.
- else
Parentheses are missing.
- print “Non equal numbers”
Parentheses are missing. print( ) is a method and hence should have opening and closing parentheses.