0% found this document useful (0 votes)
39 views

02 Error Based

The document contains examples of code with errors and the corrected code. There are various syntax errors like incorrect variable types, operators, indentation etc. For each code snippet, the error is underlined and the corrected code is shown.

Uploaded by

imshreyarajput
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

02 Error Based

The document contains examples of code with errors and the corrected code. There are various syntax errors like incorrect variable types, operators, indentation etc. For each code snippet, the error is underlined and the corrected code is shown.

Uploaded by

imshreyarajput
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Error Based Questions

Q. Find error(s) in the following code(if any) and rewrite code and
underline each correction:
(a)
x= int(“Enter value of x:”)
for in range [0,10]:
if x=y
print("They are equal")
else:
Print( "They are unequal")
Ans.
x= int(input(“Enter value of x:”))
for y in range (0,10):
if x==y:
print("They are equal")
else:
print( "They are unequal")
(b)
a, b = 0
if (a = b)
a +b = c
print( z)
Ans.
a= b = 0
if (a == b):
c = a + b
print( c)
(c)
A = int(input("Enter any number:"))
Ar = 0
for x in range(0,A,2)
Ar+=x
if x%2=0:
Print (x*10)
Else:
print (x)
print (Ar)
Ans.
A = int(input("Enter any number:"))
Ar = 0
for x in range(0,A,2):
Ar+=x
if x%2==0:
print (x*10)
else:
print (x)
print (Ar)
(d)
fee=250
0 = i
while fee=<2000:
if fee<=750:
print (fee)
fee =+ 250
else:
print( "fee"*i)
i=i+1
fee=Fee+250
Ans.
fee=250
i=0
while fee<=2000:
if fee<=750:
print (fee)
fee += 250
else:
print( "fee"*i)
i=i+1
fee=fee+250
(e)
10 = step
for e in the range(0 , step):
If e%2==0:
print(e + 1)
else:
print(e - 1
Ans.
step = 10
for e in range(0 , step):
if e%2==0:
print(e + 1)
else:
print(e - 1)
(f)
str = "Welcome to my Blog
for S in range[3,9]
Print (str(S))
Ans.
str = "Welcome to my Blog"
for S in range(3,9):
print (str[S])
(g)
For i in Range(10):
if(i==5)
break:
else:
print(i)
continue
Ans.
for i in range(10):
if(i==5):
break
else:
print(i)
continue
(h)
a = input("Enter any number")
if a%2=0:
print("Even number)
Else
print("Odd number")
Ans.
a = int(input("Enter any number"))
if a%2==0:
print("Even number")
else:
print("Odd number")
(i)
a = int(Input("Enter any number"))
b = int(input("Enter any number"))
if a=>b:
print("First number is greater"))
else:
Print("Second number is greater")
Ans.
a = int(input("Enter any number"))
b = int(input("Enter any number"))
if a>=b:
print("First number is greater")
else:
print("Second number is greater")
(j)
a = int{input("Enter any number")}
for i IN range(1:11):
print(a," * " , i , " = ", a*i)

Ans.
a = int(input("Enter any number"))
for i in range(1,11):
print(a," * " , i , " = ", a*i)
(k)
def sum(c)
s = 0
for i in Range(1, c+1)
s=s+i
return s
print(sum(5)
Ans.
def sum(c):
s = 0
for i in range(1, c+1):
s=s+i
return s
print(sum(5))
(m)
N=int(input("Enter any Number:"))
S = 0
for i in range(1,N,2)
s += 1
if i%2=0:
print("i" * 2)
else:
print("i" * 3)
print[S]
Ans.
N=int(input("Enter any Number:"))
S = 0
for i in range(1,N,2):
S += 1
if i%2==0:
print("i" * 2)
else:
print("i" * 3)
print(S)
(n)
L = [1,2,3,4,5,6,7,'a','e'
for i in L:
if i==a
break:
else:
print("A")
Ans.
L = [1,2,3,4,5,6,7,'a','e']
for i in L:
if i=='a':
break
else:
print("A")
(o)
a = {'6' : "Amit", '2' : "Sunil" : '3' : "Naina"}
for i in a:
if int(i)%3=0
print(a(i))
Ans.
a = {'6' : "Amit", '2' : "Sunil", '3' : "Naina"}
for i in a:
if int(i)%3==0:
print(a[i])
(p)
x = 5
if x > 0:
print("Positive")
else
print("Non-positive")
Ans.
x = 5
if x > 0:
print("Positive")
else:
print("Non-positive")
(q)
def add_numbers(a, b):
return a + b
result = add_numbers(5, "10")
print(result)
Ans.
def add_numbers(a, b):
return a + b
result = add_numbers(5, 10)
print(result)
(r)
def factorial(n)
if n == 0:
return 1
else:
return n * factorial(n-1)
print(factorial(5))
Ans.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
print(factorial(5))
(s)
numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
print(numbers[i])
i += 1
Ans.
numbers = [1, 2, 3, 4, 5]
i = 0
while i < len(numbers): # Corrected to use a
while loop
print(numbers[i])
i += 1
(t)
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is not greater than 5")
Ans.
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is not greater than 5")
(u)
number = input("Enter a number: ")
if number > 0:
print("Positive")
else:
print("Non-positive")
Ans.
number = int(input("Enter a number: "))
if number > 0:
print("Positive")
else:
print("Non-positive")

You might also like