Error-Finding and Output Prediction Worksheet
1. What is/are the error(s) in the following Python code?
x = 10
if x > 5
print("x is greater")
2. Identify and correct errors:
for i in [1,2,3]
print(i)
3. Point out any error(s) in:
count = 5
while count > 0
print(count)
count = count - 1
print("Done")
4. Find all errors and mention corrections:
num = int(input("Enter a number"))
if num%2 = 0:
print(“Even”)
else
print(“Odd”)
5. Identify logical errors:
for x in range(5):
print(x)
x += 1
[Link] will be the output of the following?
count = 0
while count < 3:
print("Hello")
count += 1
7. Predict the output:
x = 10
y=0
while x > y:
print(x, y)
x -= 1
y += 1
8. What is printed?
for n in range(2,8,2):
print(n)
9. How does this code execute?
for p in range(1,10):
print(p)
10. State the output produced by:
for x in [1,2,3]:
for y in [4,5,6]:
print(x, y)
11. What will be printed?
for i in range(4):
for j in range(3):
print(i + j, end=" ")
print()
12. Observe the following Python code very carefully and rewrite it after removing all errors with each
correction underlined.
Str=‟Jagdalpur”
L= length(Str)
For j in range(L)
Print(j)
13. How many times „Hello KV‟ will be printed after the execution of the following code:
for x in range(0,20,2):
print(“Hello KV”)
print(“Hello KV”*2)
14. Find out the errors in the code given below , underline each correction and write its correct version: Val =
int(input("Value:"))
Adder = 0
for C in range(1,Val,3):
Adder =+ C
if C%2 = 0;
print(C*10)
Else:
print(C*)
print(Adder)
15. Write the output of following python code
Str=‟Kendriya Vidyalaya Sangathan”
print(Str,sep=‟@”, end=‟:”)
print(“Jammu Region”,end=‟!!!”)
16. What is the output produced by the following code: D={‘rno’:[1,2,3],
‘name’:[‘ravi’,‘kavi’,‘chhavi’],‘marks’:[20,23,25]}
print([Link]())
print([Link]())
17. What will be the output of:
s = "PyThOn"
print([Link]())
print([Link]())
print([Link]())
print([Link]())
18. Fill in the blanks:
• To count the number of characters in "OpenAI", use _________
• To find if "digit123" contains only digits, use __________
19. Write Python code to demonstrate:
• count(), find(), and index() on "apple banana apple".
• endswith() and startswith() for the string "banana".
• isalpha(), isdigit(), isspace() on sample strings.
20. For the string " Data Science ":
• Remove leading/trailing spaces.
• Convert to uppercase.
• Replace a space with "_".
• Split the string into words.
21. Find and correct errors:
s = "test"
print([Link]))
s = "12345"
print([Link]))
22. Write a program to count the number of vowels in an input string.
23. Accept a string and print all words in reverse order using split() and join().
24. Given s = "python rocks", write code to:
• Capitalize only the first character.
• Replace "rocks" with "rules".
• Partition the string at the space.
25. Predict output:
msg = "We,Will,Win"
print([Link](","))
print("_".join([Link](",")))
26. True/False:
• Strings can be changed after creation.
• islower() returns True only if all letters are lowercase.
• replace() method changes all occurrences of a substring.