Error Finding Questions in Python

Here are some error correction based questions in python for Computer Science and IP Students.

 

Q 1.  Code with Error(s).

x= int(“Enter value of x:”) 
for in range [0,10]: 
           if x=y 
           print( x + y) 
              else: 
Print( x‐y)

 

Correct code after removing the Error(s) :

x= int(input(“Enter value of x:”)) 
for in range (0,10):
         if x==y: 
             print( x+y) 
         else: 
print (x‐y)

 

 

Q 2.  Code with Error(s).

a, b = 0 
if (a = b) 
a +b = c 
print( z)

 

Correct code after removing the Error(s) :

a,b = 0,0
if (a = =b) : 
c=a +b 
print(c) 

 

Q 3. Code with Error(s).

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

 

Correct code after removing the Error(s) :

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

 

 

Q 4. Code with Error(s).

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

 

Correct code after removing the Error(s) :

Val = int(raw_input("Value:")) # Error 1
Adder = 0 
for C in range(1,Val,3) : # Error 2 
              Adder+=C 
              if C%2==0 : # Error 3 
                      print( C*10 ) # Error 4 
              else: # Error 5 
                    print(C) # Error 6 
print Adder

 

Q 5. Code with Error(s).

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

 

Correct code after removing the Error(s) :

Val = 25 #Error 1
for I in range(0,Val): #Error 2 and Error 3 
                 if I%2==0: 
                         print (I+1) 
                 else: #Error 4 
                          print (I‐1)

 

Q 6. Code with Error(s).

STRING=""WELCOME 
NOTE"" 
for S in range[0,8]: 
                print (STRING(S)) 

 

Correct code after removing the Error(s) :

STRING= "WELCOME"
NOTE=" "
for S in range (0, 8) : 
            print (STRING [S])

 

Q 7. Code with Error(s).

a=int{input("ENTER FIRST NUMBER")} 
b=int(input("ENTER SECOND NUMBER")) 
c=int(input("ENTER THIRD NUMBER")) 
if a>b and a>c 
       print("A IS GREATER") 
if b>a and b>c: 
        Print(" B IS GREATER") 
if c>a and c>b: 
        print(C IS GREATER) 

 

Correct code after removing the Error(s) :

a=int(input("ENTER FIRST NUMBER"))
b=int(input("ENTER SECOND NUMBER")) 
c=int(input("ENTER THIRD NUMBER")) 
if a>b and a>c:
       print("A IS GREATER") 
if b>a and b>c
       print(" B IS GREATER") 
if c>a and c>b: 
         print("C IS GREATER ")

 

 

Q. 8 Code with Error(s)

i==1
a=int(input("ENTER FIRST NUMBER"))
FOR i in range[1, 11];
      print(a,"*=", i ,"=",a * i)

 

Correct code after removing the Error(s) :

i=1
a=int(input("ENTER FIRST NUMBER")) 
for i in range(1,11):
     print(a,"*=",i,"=",a*i) 

 

Q.9 Code with Error(s)

a="1"
while a>=10: 
      print("Value of a=",a) 
a=+1 

 

Correct code after removing the Error(s) :

a=1
while a<=10: 
       print("Value of a=",a) 
       a+=1

 

Q. 10 Code with Error(s)

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

 

Correct code after removing the Error(s) :

Num=int(input("Number:"))
sum=0
for i in range(10,Num,3):
           sum+=1
            if i%2==0:
                 print(i*2)
            else:
                 print(i*3)
print(sum)

 

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved