Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Python Error Fixing Predict Output

The document contains a series of programming questions focused on finding and correcting errors in Python code. Each question requires the identification of syntax errors and the rewriting of the code with corrections underlined. Additionally, the document includes questions about predicting the output of given code snippets.

Uploaded by

shariqbyju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Python Error Fixing Predict Output

The document contains a series of programming questions focused on finding and correcting errors in Python code. Each question requires the identification of syntax errors and the rewriting of the code with corrections underlined. Additionally, the document includes questions about predicting the output of given code snippets.

Uploaded by

shariqbyju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ERROR FINDING QUESTIONS

Q1. Find error in the following code(if any) and correct code by rewriting code and
underline the correction;‐
x= int(“Enter value of x:”)
for in range [0,10]:
if x=y
print( x + y)
else:
print( x‐y)

Q2. Rewrite the following program after finding and correcting syntactical errors and
underlining it.
a, b = 0
if (a = b)
a +b = c
print( z)

Q3. 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

Q4. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.
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)

Q5. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.
25=Val
for I in the range(0,Val)
if I%2==0:
print( I+1)
Else:
print (I‐1
Q6. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.
STRING=""WELCOME
NOTE""
for S in range[0,8]:
print (STRING(S))

Q7. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the 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)

Q8. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.
i==1
a=int(input("ENTER FIRST NUMBER"))
FOR i in range[1, 11];
print(a,"*=", i ,"=",a * i)

Q9. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.
a=”1”
while a>=10:
print("Value of a=",a)
a=+1

Q10. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.

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)

Q11. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.

weather='raining'
if weather='sunny':
print("wear sunblock")
elif weather='snow':
print("going skiing")
else:
print(weather)
OUTPUT FINDING QUESTIONS
Q1. Find output generated by the following code:
p=10
q=20
p*=q//3
q+=p=q**2
print(p, q)
Q2. Find output generated by the following code:
String Str=”Computer”
Str[‐4:]
Str*2

Q3. Find out the output of the Following –


x=20
x=x+5
x=x‐10
print (x)
x, y=x‐1,50
print (x, y)

Q4. Find out the output of the Following –


for a in range(3,10,3):
for b in range(1,a,2):
print(b, end=’ ‘)
print( )

Q5. FIND OUTPUT OF FOLLOWING


x=10
y=5
for i in range(x‐y*2):
print("%",i)

Q6. Find output generated by the following code:


x="one"
y="two"
c=0
while c<len(x):
print(x[c],y[c])
c=c+1

Q7. Find output generated by the following code:


for i in range(‐1,7,2):
for j in range(3):
print(i,j)

Q8. Find output generated by the following code:


string=”aabbcc”
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[‐1]=='b':
string=string[:2]
else:
count+=1
break
print(string)
print(count)

Q9. Find output generated by the following code:


x="hello world"
print(x[:2],x[:‐2],x[‐2:])
print(x[6],x[2:4])
print(x[2:‐3],x[‐4:‐2])
ANSWERS
Error Finding Answers
Ans 1. Correct code:‐
x= int(input(“Enter value of x:”))
for in range (0,10):
if x==y:
print( x+y)
else:
print (x‐y)

Ans 2. a,b = 0,0


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

Ans 3. Number = 250


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

Ans 4. 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

Ans 5. 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)

Ans 6. CORRECTED CODE:‐


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

Also range(0,8) will give a runtime error as the index is out of range. It shouldbe range(0,7)

Ans 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 ")
Ans 8. CORRECTED CODE
i=1
a=int(input("ENTER FIRST NUMBER"))
for i in range(1,11):
print(a,"*=",i,"=",a*i)

Ans 9. CORRECTED CODE


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

Ans 10. CORRECTED CODE


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)

Ans. 11 Corrected Code


weather='raining'
if weather=='sunny':
print("wear sunblock")
elif weather=='snow':
print("going skiing")
else:
print(weather)
OUTPUT
1. Output:‐ 60, 480 2. ANS uter
‘ComputerComputer’

3. ANS: 15 ANS 4: 1
14, 50 1 4
1 4 7

ANS 5:‐ NO OUTPUT Ans 6.: ot


nw
eo

ANS 7: ‐1 0 Ans. 8 bbcc


‐1 1 4
‐1 2
10
11
12
30
31
32
50
51
52

Ans 9: he hello wor ld


w ll
llo wo or

You might also like