AI_Assignment2[1]
AI_Assignment2[1]
##question 1
def factorial(num: int):
if num == 0:
return 1
else:
return num * factorial(num - 1)
print(factorial(4))
24
##question 2
##takes in the nth fibonacci number and prints out the series till that number
def fibonacci_numbers(n: int):
f0 = 0
f1 = 1
if (n == 0):
print(0)
elif (n == 1):
print(1)
else:
print(f0)
print(f1)
for i in range(n-1):
f2 = f0 + f1
f0 = f1
f1 = f2
print(f2)
fibonacci_numbers(2)
0
1
1
##question 3
def greatest():
a = int(input("Enter the first number"))
b = int(input("Enter the first number"))
c = int(input("Enter the first number"))
print("The maximum of the three given numbers is : " + str(max(a, b, c)))
greatest()
fromJug = fromJugCap
toJug = 0
step = 1
while ((fromJug is not d) and (toJug is not d)):
step = step + 1
if ((fromJug == d) or (toJug == d)):
break
if fromJug == 0:
fromJug = fromJugCap
step = step + 1
if toJug == toJugCap:
toJug = 0
step = step + 1
return step
return(min(Pour(n,m,d), Pour(m,n,d)))
n = 3
m = 5
d = 4
print('Minimum number of steps required is',
minSteps(n, m, d))
##question 5
def add():
a = int(input("Enter the first number"))
b = int(input("Enter the second number"))
print("The sum of the two numbers is : " + str(a + b))
add()
##question 6
def greatest():
a = int(input("Enter the first number"))
b = int(input("Enter the first number"))
c = int(input("Enter the first number"))
print("The maximum of the three given numbers is : " + str(max(a, b, c)))
greatest()