Error Finding Questions in Python class 11-12 Computer Science

Error Finding Questions in Python class 11-12 Computer Science

 

Find error in the following codes(if any) and correct code by rewriting code and underline the correction (Q-1 to Q-14)

 

Q 1. 

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

 

Correct code:

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

 

 

Q 2. 

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

 

Correct code:

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

 

Q 3. 

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

 

Correct code:


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

 

 

Q 4. 

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:


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.

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

 

Correct code:

 

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.

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

 

Correct code:

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

 

Q 7.

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:

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 ")

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *