Anjeev Singh Academy

20+ Error Finding Questions Solved in Python

Hello Dear Students

In this post, I am sharing important python error finding and correcting questions with valid reasons. These questions help you in understanding python concepts.

All the best.

Q 1: Rewrite it after removing all syntactical errors with each correction underlined.

DEF execmain():
x = input(“Enter a number:”)
if (abs(x)= x):
print”You entered a positive number”
else:
x=*-1
print”Number made positive:”x

execmain()
Answer:

def execmain():
     x = input(“Enter a number:”)
     if (abs(x) = = x):
          print(“You entered a positive number)
     else:
          x *= -1
 
  print (“Number made positive:“, x)
 

execmain()
Reason:-
def   => must be in small letter
= =   => use for comparison
() => in the print argument must be enclosed in ()
*=  => first arithmetic then assignment
 ,    => in print() values are separated by , (comma)
 

Q 2: Rewrite it after removing all syntactical errors with each correction underlined.

STRING=””HAPPY NEW YEAR”
for S in range[0,8]:
print STRING(S)
print S+STRING
Answer:

STRING = HAPPY NEW YEAR
for S in range(
0,len(STRING)):
    
print(STRING[S])
     print (
S, STRING)
Reason:-
•Only one double quote is required in beginning.
•In range() , curved bracket is required
•Use len(STRING) instead of value.
•print need () and to access the member need to use []
 

Q 3: Rewrite it after removing all syntactical errors with each correction underlined.

def checkval:
  x = input(“Enter a number”)
  if x % 2 = 0:
     print x,”is even”
  else if x<0:
    print x,”should be positive”
  else;
     print x,”is odd”
Answer:

def checkval():
   x =
int(input(“Enter a number:”))
   if x % 2
== 0:
       print
(x, “is even”)
  
elif x<0:
       print
(x, ”should be positive”)
   else:
       print
(x, ”is odd”)
Reason:-

•Function header must contain ()
•int( ) to convert string to integer, because input returns string value
•= = is use for comparision
•elif is use to check condition with else
•Use ( ) with print to display values
 

Q 4: Rewrite it after removing all syntactical errors with each correction underlined.

25=Val
for I in the range(0,Val)
 if I%2=0:
    print( I+1)
 Else:
    print (I-1)
Answer:

Val = 25
for I in range(0,Val
):
 if I%2
==  0:
    print( I+1)
 else:
    print (I-1)
Reason:-

•Variable must be left to assignment
•the is not a valid keyword in for.
•: is required at the end of for statement
•= = is use for comparison
•else is a keyword, used in small letter
 

Q 5: Rewrite it after removing all syntactical errors with each correction underlined.

Num = int(rawinput(“Number:”))
 Sum = 0
 for i in range(10,Num,3) Sum+=i
    if i%2=0:
       print ( i*2)
   Else:
      print ( i*3 print Sum)
Answer:

Num = int(input(“Number:”))
Sum = 0
 for i in range(10,Num,3) :
    Sum += i
    if I % 2 == 0:
       print ( i*2)
    else:
      print ( i*3)
print (Sum)
Reason:-

•      rawinput() not available in python
•      : is required at the end of for statement
•      Sum+=i will be after for.
•      = = is use for comparison
•      else is a keyword, used in small letter
•      print(Sum) should be outside the loop
 

Q 6: Rewrite it after removing all syntactical errors with each correction underlined.

 a = int(input(“Value:”))
 b = 0
 for c in range(1,a,2)
 b + = c if c%2 = 0:
 Print (c*3) Else:
 print (c*) print (b)
Answer:

 a = int(input(“Value:”))
 b = 0
 for c in range(1,a,2) :
      b + = c
      if c%2 == 0:
          print (c*3)
      else:
          print (c*2)
  print (b)
Reason:-

•      : is required at the end of for statement
•      Indentation is required in all statement after for
•      = = is use for comparison
•      else is a keyword, used in small letter
•      Print(b) should be outside the loop
 

Q 7: Rewrite it after removing all syntactical errors with each correction underlined.

def main():
 r = input(‘enter any radius: ‘)
 a = pi * math.pow(r,2)
 print(“Area = “ + a)
Answer:

import math
def main():
   r = int(input(‘enter   any radius:’) )
   a = math.pi *math.pow(r,2)
  
   print(“Area = ”  , a)
Reason:-

•      Import math module to use mathematical function
•      Convert string to integer
•      Use math.pi instead of pi
•      Use comma (,) to separate multiple value in print() 

Q 8: Rewrite it after removing all syntactical errors with each correction underlined.

Def checkNumber(N):
    status = N%2
    return
 
#main-code
num=int( input(” Enter a number to check :))
k=checkNumber(num)
 
if k = 0:
    print(“This is EVEN number”)
else:
    print(“This is ODD number”)
Answer:

def checkNumber(N):
    status = N%2
    return status
 
#main-code
num = int(input(” Enter a number to check : “))
k = checkNumber(num)
if k == 0:
    print(“This is EVEN number”)
else:
    print(“This is ODD number”)
Reason:-

·       def must be in small letter
·       Function should return a value of status
·       String must be enclosed in double quotes.
·       == is use for comparison.

Q 9: Rewrite it after removing all syntactical errors with each correction underlined.

define reverse(num):
     rev = 0
     While num > 0:
          rem == num %10
          rev = rev*10 + rem
          num = num//10
      return rev
print(reverse(1234))
Answer:
def reverse(num):
      rev = 0
      while num > 0:
           rem = num %10
           rev = rev*10 + rem
           num = num//10
      return rev
 
 print(reverse(1234))
Reason:-

·       def is use to define a function
·       while is a keyword, written in small letter
·       = is use for assignment, while == is use for comparison
·       return rev must be indented

Q 10: Rewrite it after removing all syntactical errors with each correction underlined.

def sum(arg1, arg2):
      total = arg1 + arg2;
      print(”Total:”, total)
return total;
 
sum(10,20)
print(”Total:”,total)
Answer:

def sum(arg1, arg2):
      total = arg1 + arg2;
      print(”Total:”,total)
      return total;
 
total = sum(10, 20)
print(”Total:”, total)
Reason:-

·       def is use to define a function
·       while is a keyword, written in small letter
·       = is use for assignment, while == is use for comparison
·       return rev must be indented

Q 11: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.

Runs = ( 10, 5, 0, 2, 4, 3 )
for I in Runs:
if I=0:
print(Maiden Over)
else
print(Not Maiden)
Answer:

Runs = ( 10, 5, 0, 2, 4, 3 )
for I in Runs:
if I == 0:
print(“Maiden Over”)
else:
print(“Not Maiden”)
Reason:-

* = is use for assignment, while == is use for comparison
*  use ” ” to print message.
* use : after else

Q 12: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.

input(‘Enter a word’,W)
if W = ‘Hello’
print(‘Ok’)
else:
print(‘Not Ok’)
Answer:

W = input(‘Enter a word’)
if W == ‘Hello’ :
print(‘Ok’)
else:
print(‘Not Ok’)
Reason:-

* input() function return a string value, which need to assign to a variable.
* = is use for assignment, while == is use for comparison
* use : at the end of if header
*  de-indent the else:

Q 13: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.

250 = Number
WHILE Number<=1000:
if Number=>750:
print Number
Number=Number+100
else
print Number*2
Number=Number+50
Answer:

Number = 250
while Number <= 1000:
if Number >= 750:
print (Number)
Number = Number + 100
else:
print (Number*2)
Number = Number + 50
Reason:-

* Variable must be before assignment operator
* while should be in small letter, it is a keyword
* use >=
* use : at the end of else header

Q 14: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.

“HELLO”=String
for I in range(0,len(String)–1)
if String[I] => “M”:
print(String[I], “*”
Else:
print(String[I-1])
Answer:

String = “HELLO”
for I in range(0, len(String)–1) :
if String[I] >= “M”:
print(String[I], “*”)
else:
print(String[I-1])
Reason:-

* Variable must be before assignment operator
* use : at the end of for header
* use >= instead of =>
* use ) at the end of print statement
* use else instead of Else

Q 15: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.

Val = int(input(“Value:”))
Adder = 0
for C in range(1,Val,3)
Adder += C
if C%2 = 0:
Print C*10
Else:
print(C)
print(Adder)
Answer:

Val = int(input(“Value:”))
Adder = 0
for C in range(1,Val,3) :
Adder += C
if C%2 == 0:
print(C*10)
else:
print(C)
print(Adder)
Reason:-

* use : at the end of for loop header
* use == instead of = for comparison
* use print( ) instead of Print( )
* use else instead of Else

Q 16: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code. [CBSE 2018 COMPARTMENT]

Num = int(input(“Number:”))
Sum = 0
for i in range(10, Num, 3)
Sum += i
if i%2 = 0:
print( i * 2 )
Else:
print(i * 3)
print Sum
Answer:

Num = int(input(“Number:”))
Sum = 0
for i in range(10, Num, 3) :
Sum += i
if i%2 == 0:
print( i * 2 )
else:
print(i * 3)
print(Sum)
Reason:-

* use : at the end of for loop header
* use == instead of = for comparison
* use else instead of Else
* use print(Sum) instead of print Sum

Q 17: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code. [CBSE 2017 ]

STRING = “”WELCOME
NOTE “”
for S in range[0,8]:
print(STRING(S) )
print(S+STRING)
Answer:

STRING = “WELCOME”
NOTE = “”
for S in range(0, 8):
print(STRING(S) )
print(S , STRING)
Reason:-

* String value must be enclosed in ” “
* use = to assign a empty string to NOTE
* use ( ) with range function.
* use [ ] to access the element of string i.e. STRING[S]
* Integer can not be concatenated with string. So use the, (comma) in place of +

Q 18: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code. [CBSE 2016]

for Name in [Ramesh, Suraj, Priya ]
IF Name[0] = ‘S’ :
print(Name)
Answer:

for Name in [“Ramesh”, “Suraj”, “Priya” ] :
if Name[0] == ‘S’ :
print(Name)
Reason:-

* String value must be enclosed in ” “
* if must be small letter. It is a keyword.
* use == to compare

Q 19: Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code. [CBSE 2015]

def Tot(Number) : #Method to find Total
Sum=0
for C in Range (1, Number+1):
Sum += C
RETURN Sum

print Tot[3] #Function Calls
print (Tot[6])
Answer:

def Tot(Number) : #Method to find Total
Sum = 0
for C in range (1, Number+1):
Sum += C
return Sum

print (Tot[3]) #Function Calls
print (Tot[6])
Reason:-

* range() must be in small letter
* return must be in small letter
* use () with print function

More questions will be uploaded soon.

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top