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

AI Class9 Python Programs

The document contains a series of Python programs that demonstrate various basic programming concepts, including input/output, arithmetic operations, control structures, and list manipulations. Each program is designed to perform specific tasks such as calculating sums, finding areas, checking even/odd numbers, and generating patterns. The examples are straightforward and serve as practical exercises for beginners learning Python.

Uploaded by

gamerscaler
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

AI Class9 Python Programs

The document contains a series of Python programs that demonstrate various basic programming concepts, including input/output, arithmetic operations, control structures, and list manipulations. Each program is designed to perform specific tasks such as calculating sums, finding areas, checking even/odd numbers, and generating patterns. The examples are straightforward and serve as practical exercises for beginners learning Python.

Uploaded by

gamerscaler
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programs

Program 1:Python program to print School name, Address and City


school_name = input("Enter your school name: ")
address = input("Enter school address: ")
city = input("Enter city: ")
print("\n--- School Details ---")
print("School Name:", school_name)
print("Address:", address)
print("City:", city)

Program 2:Python program to find sum of two numbers.


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)

Program 3:Python program to find sum and average of three numbers.


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
sum = a + b + c
average = sum / 3
print("Sum:", sum)
print("Average:", average)

Program 4:Python program to find square and cube of number.


num = int(input("Enter a number: "))
print("Square:", num ** 2)
print("Cube:", num ** 3)

Program 5:Python program to find area and perimeter of a rectangle.


length = float(input("Enter length of rectangle: "))
breadth = float(input("Enter breadth of rectangle: "))
rect_area = length * breadth
rect_perimeter = 2 * (length + breadth)
print("Rectangle Area:", rect_area)
print("Rectangle Perimeter:", rect_perimeter)
Program 6:Python program to find simple interest
p = float(input("Enter principal amount: "))
r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))
si = (p * r * t) / 100
print("Simple Interest:", si)

Program 7:Python program to perform arithmetic operations on two integers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Exponentiation:", a ** b)

Program 8:Python program to find check given number is even or odd


num = int(input("Enter a number: "))

if num % 2 == 0:
print("The number is Even")
else:
print("The number is Odd")

Program 9:Python program to check the number is positive or negative


num = float(input("Enter a number: "))

if num > 0:
print("The number is Positive")
elif num < 0:
print("The number is Negative")
else:
print("The number is Zero")
Program 10:Python program to find the largest number among three
numbers using if-else
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

if a >= b and a >= c:


print("The largest number is:", a)
elif b >= a and b >= c:
print("The largest number is:", b)
else:
print("The largest number is:", c)

Program 11:Python program to print natural numbers up to a given number n


using a while loop.
n = int(input("Enter a number: "))
i=1

print("Natural numbers up to", n, ":")


while i <= n:
print(i)
i += 1

Program 12:Python program to calculate the sum of natural numbers up to a


given number n using a loop.
n = int(input("Enter a number: "))
total = 0

for i in range(1, n + 1):


total += i

print("Sum of natural numbers up to", n, "is:", total)

Program 13:Python program to print the multiplication table of a given


number using a loop.
num = int(input("Enter a number: "))

print("\nMultiplication Table of", num)


for i in range(1, 11):
print(num, "×", i, "=", num * i)
Program 14:Python program to print a triangle pattern of stars(*)
Pattern 1 Pattern 2
* *****
** ****
*** ***
**** **
***** *
n = int(input("Enter number of rows: "))
print("\nPattern 1:")
for i in range(1, n + 1):
print("* " * i)

print("\nPattern 2:")
for i in range(n, 0, -1):
print("* " * i)

Program 15:Create a list num=[23,12,5,9,65,44]


i)print the length of the list
ii)print the elements from second to fourth position using positive indexing
iii)print the elements from position third to fifth using negative indexing
num = [23, 12, 5, 9, 65, 44]
print("Length of the list:", len(num))
print("Elements from 2nd to 4th position (positive indexing):", num[1:4])
print("Elements from 3rd to 5th position (negative indexing):", num[-4:-1])

Program 16:
Create a list of first 10 even numbers, add 1 to each list item and print the
final list.
even_numbers = [i * 2 for i in range(1, 11)]
print("original list:", even_numbers)
modified_list = [num + 1 for num in even_numbers]
print("Modified list:", modified_list)

Program 17:
Create a list List_1=[10,20,30,40].Add elements [14,15,12] using extend
function. Sort the final list in ascending order and print it.
List_1 = [10, 20, 30, 40]
List_1.extend([14, 15, 12])
List_1.sort()
print(List_1)

You might also like