0% found this document useful (0 votes)
3 views3 pages

Python Code Review Assignment

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)
3 views3 pages

Python Code Review Assignment

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

Full Name: Vangala Supriya

Contact Number: 9346727510

Email ID: Supriya.vangala03@[Link]

Task1: Python Code Review and Error Correction

Snippet 1
Error: Missing colon after function definition.

Corrected Code:

def add_numbers(a, b):


return a + b
print(add_numbers(5, 10))

Explanation: Function definitions must end with a colon.

Snippet 2
Error: String not closed with quotation marks.

Corrected Code:

name = "Alice"
print("Hello, " + name)

Explanation: Strings must be enclosed in matching quotes.

Snippet 3
Error: Missing colon after for loop.

Corrected Code:

for i in range(5):
print("Number:", i)

Explanation: Loop headers require a colon.

Snippet 4
Error: Index out of range.

Corrected Code:
my_list = [1, 2, 3, 4, 5]
print("The fifth element is:", my_list[4])

Explanation: Lists are zero-indexed. Fifth element is at index 4.

Snippet 5
Error: Indentation missing in function body.

Corrected Code:

def greet(name):
print("Hello " + name)
greet("Bob")

Explanation: Function body must be indented.

Snippet 6
Error: input() returns string, comparison with integer fails.

Corrected Code:

age = int(input("Enter your age: "))


if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

Explanation: Cast input to int for numeric comparison.

Snippet 7
Error: No error.

Corrected Code:

def multiply(a, b):


result = a * b
return result
print(multiply(4, 5))

Explanation: Code is already correct.

Snippet 8
Error: Missing colon in while loop.
Corrected Code:

count = 10
while count > 0:
print(count)
count -= 1
print("Countdown complete!")

Explanation: Loop headers must end with a colon.

You might also like