0% found this document useful (0 votes)
42 views5 pages

Ai Project Python

Uploaded by

apparentlyyes69
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)
42 views5 pages

Ai Project Python

Uploaded by

apparentlyyes69
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
You are on page 1/ 5

PYTHON PROGRAM 1:

a=7
b=2
# addition
print ('Sum: ', a + b)
# subtraction
print ('Subtraction: ', a - b)
# multiplication
print ('Multiplication: ', a * b)
# division
print ('Division: ', a / b)
# floor division
print ('Floor Division: ', a // b)
# modulo
print ('Modulo: ', a % b)
# a to the power b
print ('Power: ', a ** b)
# assign the sum of a and b to a
a += b # a = a + b
print(a)
print (a > b) # True
# equal to operator
print('a == b =', a == b)
# not equal to operator
print('a != b =', a != b)
# greater than operator
print('a > b =', a > b)
# less than operator
print('a < b =', a < b)
# greater than or equal to operator
print('a >= b =', a >= b)
# less than or equal to operator
print('a <= b =', a <= b)
OUTPUT:
PYTHON PROGRAM 2:
age = int(input("Enter age : "))
if age >= 18:
print ("Eligible for Voting!")
else:
print ("Not Eligible for Voting!")
OUTPUT:

PHYTHON PROGRAM 3:
print("The First 10 Natural Numbers")
for i in range(1, 11):
print(i)
# using while loop
i=1
while i<11:
print(i)
i=i+1
OUTPUT:
PYTHON PROGRAM 4:
#Taking user input
num = int(input('Enter a number:'))
if num < 0:
num = input('Please enter a positive number:')
else:
sum = 0
#Loop to iterate till zero
while(num > 0):
sum += num
num -= 1
print("The sum of the natural numbers is:", sum)
OUTPUT:

PYTHON PROGRAM 5:
def personal_details():
name, age = "Vedant", 13
address = "Pune,Maharashtra,India"
print("Name: {}\nAge: {}\nAddress: {}".format(name, age, address))
personal_details()
OUTPUT:

PHYTHON PROGRAM 6:
1.
def pattern(n):
for i in range(0,n):
for j in range (0,i+1):
print("*",end="")
print()
n=5
pattern(n)
OUTPUT 1:

2.
def pattern(n):
for i in range(n,0,-1):
for j in range (0,i):
print("*",end="")
print()
n=5
pattern(n)
OUTPUT 2:

PYTHON PROGRAM 7:
l=int(input ("Length : "))
w=int(input("Width : "))
area=l*w
perimeter=2*(l+w)
print("Area of Rectangle : ",area)
print("Perimeter of Rectangle : ",perimeter
OUTPUT:

You might also like