AI Practical File Part 1 2024-25
AI Practical File Part 1 2024-25
Output :
The sum of 1.5 and 6.3 is 7.8
Output :
Enter first number: 1.5
Enter second number: 6.3
The sum of two numbers : 7.8
Output :
The value of x after swapping: 10
The value of y after swapping: 5
Output :
The square root of 8.000 is 2.828
Output :
The solutions are (-3+0j) and (-2+0j)
Q8. Python Program to find the largest number among the three input numbers
Ans.
# Python program to find the largest number among the three input numbers
# change the values of num1, num2 and num3
# for a different result
num1 = 10
num2 = 14
num3 = 12
# uncomment following lines to take three numbers from user
#num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Output :
The largest number is 14
Output (I) :
Enter a number: 2
Positive number
(II)
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
Output (II) :
Enter a number: 0
Zero
Output (II) :
Enter a number: 18
18 is Even
Q11. Write a Python Program to Find the Factorial of a Number
Ans.
# Python program to find the factorial of a number provided by the user.
# change the value for a different result
num = 7
# To take input from the user
#num = int(input("Enter a number: "))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output :
The factorial of 7 is 5040
Output :
How many terms? 7
Fibonacci sequence:
0
1
1
2
3
5
8