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

Class 9 AI Practical Python Programs

The document outlines several practical programs using Python for generative AI applications, including a text generator, AI chatbot, poem generator, and basic arithmetic operations. Each program includes its aim, code, and result, demonstrating various programming concepts such as random text generation, user interaction, and conditional statements. Overall, it serves as a guide for implementing simple AI-related functionalities in Python.

Uploaded by

7500589559manvi
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)
2 views3 pages

Class 9 AI Practical Python Programs

The document outlines several practical programs using Python for generative AI applications, including a text generator, AI chatbot, poem generator, and basic arithmetic operations. Each program includes its aim, code, and result, demonstrating various programming concepts such as random text generation, user interaction, and conditional statements. Overall, it serves as a guide for implementing simple AI-related functionalities in Python.

Uploaded by

7500589559manvi
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

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.

You might also like