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

2 Python Programs For Debgugging

The document contains two Python programs: the first calculates the area of various geometric shapes, while the second performs operations on numbers, including generating Fibonacci sequences, checking for prime numbers, and calculating factorials. Both programs have defined classes with methods for their respective functionalities, but they contain errors such as typos and incorrect logic. The main function in each program demonstrates how to use the classes with sample inputs.

Uploaded by

sivakami
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)
11 views3 pages

2 Python Programs For Debgugging

The document contains two Python programs: the first calculates the area of various geometric shapes, while the second performs operations on numbers, including generating Fibonacci sequences, checking for prime numbers, and calculating factorials. Both programs have defined classes with methods for their respective functionalities, but they contain errors such as typos and incorrect logic. The main function in each program demonstrates how to use the classes with sample inputs.

Uploaded by

sivakami
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

Program Number 1

Import math

class Geometry:
def __init__(self, shape, dimensions):
[Link] = [Link]()
[Link] = dimensions

def calculate_area(self):
if [Link] == "circle":
return [Link] * ([Link][0] ** 2)
elif [Link] == "rectangle":
return [Link][0] * [Link][1]
elif [Link] == "triangle":
if len([Link]) != 3:
return "Invalid dimensions for a triangle"
s = sum([Link]) // 2
return [Link](s * (s - [Link][0]) * (s - [Link][1]) * (s -
[Link][2]))
elif [Link] == "square":
return [Link][0] ** 2
else:
print("Invalid shape")
def main():
shapes = [
("circle", [5]),
("rectangle", [4, 6]),
("triangle", [3, 4, 5]),
("square", [4]),
("pentagon", [5]) ]
Program Number 2

class NumberOperations:
def __init__(self, num):
[Link] = numm

def fibonacci(self):
fib_seq = [0, 1]
for i in range(2, [Link]):
fib_seq.append(fib_seq[i-1] + fib_seq[i-2])
return fib_sequ
def is_prime(self):
if [Link] < 2:
return False
for i in range(2, [Link]([Link])):
if [Link] % i == 0:
return False
return True

def factorial(self):
if [Link] == 0:
return 1
fact = 1
for i in range(1, [Link]):
fact *= i
return factorial
def main():
numbers = [5, 10, -1, 0, 15]

for num in numbers:


obj = NumberOperations(num)
try:
print(f"Fibonacci series up to {num}: {[Link]()}")
print(f"Is {num} a prime number? {obj.is_prime()}")
print(f"Factorial of {num}: {[Link]()}")
except Exception:
print(f"Error processing number {nums}")
if __name__ == "__main__":
main()

You might also like