0% found this document useful (0 votes)
2 views4 pages

Python Error Corrections

The document presents five Python programs with incorrect code snippets and their corrected versions. Each program addresses a specific task, such as summing digits, counting vowels, calculating factorials, checking for prime numbers, and finding the maximum in a list. The corrections primarily involve syntax errors and logical adjustments to ensure proper functionality.

Uploaded by

nakulcomputer123
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)
2 views4 pages

Python Error Corrections

The document presents five Python programs with incorrect code snippets and their corrected versions. Each program addresses a specific task, such as summing digits, counting vowels, calculating factorials, checking for prime numbers, and finding the maximum in a list. The corrections primarily involve syntax errors and logical adjustments to ensure proper functionality.

Uploaded by

nakulcomputer123
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

Python Programs with Errors and Corrections

PROGRAM 1 — Sum of Digits


Wrong Code:

def sumdigit(num)

s=0

while num > 0

d = num % 10

s=s+d

num = num / 10

return s

Correct Code:

def sumDigit(num):

s=0

while num > 0:

d = num % 10

s=s+d

num = num // 10

return s

PROGRAM 2 — Count Vowels


Wrong Code:

def vowcount(s):

v = "aeiouAEIOU"

c=0

for ch in s
if ch in v

c=c+1

return count

Correct Code:

def vowCount(s):

v = "aeiouAEIOU"

c=0

for ch in s:

if ch in v:

c=c+1

return c

PROGRAM 3 — Factorial
Wrong Code:

def fact(n):

f=1

for i in range(1,n)

f=f*i

retrun f

Correct Code:

def fact(n):

f=1

for i in range(1, n + 1):

f=f*i

return f
PROGRAM 4 — Prime Check
Wrong Code:

def prime(n):

for i in range(2,n//2):

if n%i = 0:

return "Not Prime"

else:

return "Prime"

Correct Code:

def prime(n):

for i in range(2, n // 2 + 1):

if n % i == 0:

return "Not Prime"

return "Prime"

PROGRAM 5 — Maximum in List


Wrong Code:

def maxList(L):

m = L[1]

for i in L:

if i > m

m == i

return m

Correct Code:

def maxList(L):

m = L[0]
for i in L:

if i > m:

m=i

return m

You might also like