Competative Practical
Competative Practical
Bachelor of Technology
In
Artificial Intelligence and Machine Learning
Submitted By
Session 2024-25
DECLARATION BY THE CANDIDATE
We hereby declare that the work entitled “Console Application and Python Scripts” is our
work, conducted under the supervision of Mr. Khemchand Shakywar (Assistant Professor)
& Ms. Aditi Samadhiya (Assistant Professor), during the session Aug-Dec 2024. The report
submitted by us is a record of bonafide work carried out by me.
We further declare that the work reported in this report has not been submitted and will not be
submitted, either in part or in full, for the award of any other degree or diploma in this institute
or any other institute or university.
--------------------------------
Date: 22.11.2024
Place: Gwalior
This is to certify that the above statement made by the candidates is correct to the best of our
knowledge and belief.
ACKNOWLEDGEMENT
We would like to express our greatest appreciation to all the individuals who have helped and
supported us throughout this report. We are thankful to the whole Centre for Artificial
Intelligence for their ongoing support during the experiments, from initial advice and provision
of contact in the first stages through ongoing advice and encouragement, which led to the final
report.
A special acknowledgement goes to our colleagues who help us in completing the file and by
exchanging interesting ideas to deal with problems and sharing the experience.
We wish to thank the faculty and supporting staff for their undivided support and interest which
inspired us and encouraged us to go my own way without whom we would be unable to
complete my project.
In the end, We want to thank our friends who displayed appreciation for our work and
motivated us to continue our work.
-----------------------------------------------
Prof. Khemchand Shakywar
Faculty Mentor Assistant Professor
Centre for Artificial Intelligence
-----------------------------------------------
Prof. Aditi Samadhiya
Faculty Mentor Assistant Professor
Centre for Artificial Intelligence
Develop a console application that solves classic dynamic programming
problems like the Fibonacci sequence, coin change problem, and longest
common subsequence. Users can input problem parameters, and the
program outputs the solution.
CODE:
def fibonacci(n):
if n <= 0:
return "Input must be a positive integer."
dp = [0] * (n + 1)
dp[1] = 1
for i in range(2, n + 1):
dp[i] = dp[i - 1] + dp[i - 2]
return dp[n]
def main():
while True:
print("\nDynamic Programming Problems:")
print("1. Fibonacci Sequence")
print("2. Coin Change Problem")
print("3. Longest Common Subsequence")
print("4. Exit")
choice = input("Select an option (1-4): ")
if choice == '1':
n = int(input("Enter the Fibonacci index (n): "))
result = fibonacci(n)
print(f"Fibonacci({n}): {result}")
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
OUTPUT
Implement a Python script that solves divide and conquer problems like
finding the maximum subarray sum or computing the nth Fibonacci
number efficiently using the divide and conquer approach.
CODE:
def max_subarray_sum(arr, low, high):
"""Divide and Conquer: Find the maximum subarray sum"""
if low == high:
return arr[low]
right_sum = float('-inf')
sum_ = 0
for i in range(mid + 1, high + 1):
sum_ += arr[i]
if sum_ > right_sum:
right_sum = sum_
def fibonacci_divide_and_conquer(n):
"""Divide and Conquer: Compute nth Fibonacci number."""
def fib_helper(k):
if k == 0:
return (0, 1) # Base case: (F(0), F(1))
a, b = fib_helper(k // 2)
c = a * ((b << 1) - a)
d=a*a+b*b
if k % 2 == 0:
return (c, d)
else:
return (d, c + d)
if n < 0:
return "Input must be a non-negative integer."
return fib_helper(n)[0]
def main():
while True:
print("\nDivide and Conquer Problems:")
print("1. Maximum Subarray Sum")
print("2. Fibonacci Number")
print("3. Exit")
choice = input("Select an option (1-3): ")
if choice == '1':
arr = list(map(int, input("Enter the array (space-separated): ").split()))
result = max_subarray_sum(arr, 0, len(arr) - 1)
print(f"Maximum Subarray Sum: {result}")
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
OUTPUT