Artificial Intelligence Practical Programs on Generative AI
1. Text Generator Program
Aim: To generate random text using Python.
Program:
import random
texts = [
"Artificial Intelligence is changing the world.",
"Python is a powerful programming language.",
"Generative AI creates new content."
]
print([Link](texts))
Result:
The program generates random text each time it runs.
2. AI Chatbot Program
Aim: To create a simple AI chatbot using Python.
Program:
while True:
user = input("You: ").lower()
if user == "hi":
print("AI: Hello!")
elif user == "how are you":
print("AI: I am fine.")
elif user == "bye":
print("AI: Goodbye!")
break
else:
print("AI: I am learning new things.")
Result:
The chatbot responds based on user input.
3. Poem Generator Program
Aim: To generate a simple poem using Python.
Program:
import random
lines = [
"AI makes life smart,",
"Learning day by day,",
"Helping humans grow,",
"In a special way."
]
for i in range(2):
print([Link](lines))
Result:
The program generates a short poem.
4. Sum, Average and Product of Two Numbers
Aim: To calculate sum, average and product of two numbers.
Program:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)
print("Average:", (a + b) / 2)
print("Product:", a * b)
Result:
The program displays sum, average and product.
5. Working of For Loop
Aim: To demonstrate the working of a for loop.
Program:
for i in range(1, 6):
print(i)
Result:
The program prints numbers from 1 to 5.
6. Conditional Statements Program
Aim: To demonstrate conditional statements in Python.
Program:
num = int(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
Result:
The program checks whether the number is positive, negative or zero.