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.

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.