0% found this document useful (0 votes)
4K views

Answers For Debugging Exercises: Chapter 3: Find The Output

This document provides answers to debugging exercises from a Python programming textbook. It includes 14 questions with outputs or errors to debug code snippets related to conditionals, loops, ranges, continue and break statements.

Uploaded by

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

Answers For Debugging Exercises: Chapter 3: Find The Output

This document provides answers to debugging exercises from a Python programming textbook. It includes 14 questions with outputs or errors to debug code snippets related to conditionals, loops, ranges, continue and break statements.

Uploaded by

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

Thareja: Problem Solving and Programming with Python

Answers for Debugging Exercises: Chapter 3

Find the Output


1.
years = 200
if(years == 100):
print( "Century")
elif(years == 75):
print ("Platinum Jublee")
elif(years == 50):
print ("Half Century")
elif(years == 25):
print ("Silver Jublee")
elif(years == 10):
print ("Decade")
else:
print ("Nothing")
Ans. Nothing

2. num = 100
if num > 30:
print("30")
if num<50:
print("50")
if num==7:
print("70")
Ans. 30

3.
if x == 50:
print("Yeah")
else:
print("Try Again")
Ans. Try Again

©Oxford University Press. All rights reserved. 1


Thareja: Problem Solving and Programming with Python

4.
num = 100
if (num + 1) > 100:
if (num * 2) >= 200:
print( "You win")
else:
print( "Try Again")
a. You Win b. Try Again c. There is no output
Ans. (a)

5.
num = 70
if num == 50:
print( "50")
elif num == 10:
print( "10")
elif num == 70:
print( "70")
else:
print("Number is not 50, 10 or 70")
Ans. 70

6.
if(10 == 10) and (10+20>30):
print("Done")
else:
print("Do It")
Ans. Do It

7. >>>not 10>70
Ans. True

©Oxford University Press. All rights reserved. 2


Thareja: Problem Solving and Programming with Python

8.
if not True:
print("10")
elif not(10+10 == 30):
print("20")
else:
print("30")
Ans. 20
9.
If 10 + 30 == 60:
print("Best")
else:
print("Worst")
Ans. Worst

10.
a = 10
b = 20
if not 10 + 10 == b or a == 40 and 70== 80:
print (“Yes”)
elif a != b:
print("No")
Ans. No

11.
i=1
while i<=6:
print(i, end = " ")
i=i+1
print("Done")
Ans.
1 2 3 4 5 6
Done

©Oxford University Press. All rights reserved. 3


Thareja: Problem Solving and Programming with Python

12.
i=0
while i<10:
i = i + 1
if(i == 5):
print( "\n Continue")
continue
if(i==7):
print("\n Breaking")
break
print( i, end = " ")
print( "\n Done")
Ans.
1 2 3 4
Continue
6
Breaking
Done

13.

for i in range(5):
print("hello!", end = " ")
OUTPUT
hello! hello! hello! hello! hello!

14.
for i in range(10):
if not i%2==0:
print(i+1)
Ans. Print all the even numbers between 2 and 10

©Oxford University Press. All rights reserved. 4


Thareja: Problem Solving and Programming with Python

Find the Error


1. Indentation error
2. Brackets missing in the while statement
3. No colons in the for statement
4. i is not initialized and no brackets in while statement
5. No brackets in while and semicolon is not allowed in while
6. No error

©Oxford University Press. All rights reserved. 5

You might also like