Revision
Artificial Intelligence (Subject Code: 417)
Python Programs – Class IX
Variable Naming Convention
A variable name must start with a letter or the
underscore character. Example a, _a
A variable name cannot start with a number. Example 1a
A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ ) Example a, a1, a_1,
Variable names are case-sensitive (Example abc, Abc and
ABC are three different variables)
A keyword cannot be used as a variable. Example for,
while, if, else, elif
Data Type
Integer – for numeric values
Float – for decimal values
String – for character values
Arithmetic Operators
a=10
b=20
c=a+b
print("Result is ",c)
Output is 30
a=10
b=20
c=a-b
print("Result is ",c)
Output is -10
a=2
b=5
c=a*b
print("Result is ",c)
Output is 10
a=20
b=5
c=a/b
print("Result is ",c)
Output is 4.0
a=20
b=10
c=a//b
print("Result is ",c)
Output is 4
a=20
b=5
c=a//b
print("Result is ",c)
Output is 4
a=2
b=5
c=a**b
print("Result is ",c)
Output is 4
# Write a program to add two digits
no1=int(input("Enter First Number"))
no2=int(input("Enter Second Number"))
total=no1+no2
print("total is ",total)
# Write a program to add three digits
no1=int(input("Enter First Number"))
no2=int(input("Enter Second Number"))
no3=int(input("Enter Third Number"))
total=no1+no2+no3
print("total is ",total)
# Write a program to add five digits
no1=int(input("Enter First Number"))
no2=int(input("Enter Second Number"))
no3=int(input("Enter Third Number"))
no4=int(input("Enter Fourth Number"))
no5=int(input("Enter Fifth Number"))
total=no1+no2+no3+no4+no5
print("total is ",total)
# Write a program to add marks of 5 subjects and calculate the
percentage
eng=int(input("Enter Marks of English"))
hin=int(input("Enter Marks of Hindi"))
mat=int(input("Enter Third Number"))
sst=int(input("Enter Fourth Number"))
sci=int(input("Enter Fifth Number"))
total=eng+hin+mat+sst+sci
print("total: ",total)
per=total/500*100
print("percentage: ",per)
# Write a program to calculate the area of rectangle
le=int(input("Enter Length"))
br=int(input("Enter Breadth"))
area=le*br
print("area of rectangle: ",area)
# Write a program to calculate the perimeter of rectangle
le=int(input("Enter Length"))
br=int(input("Enter Breadth"))
peri=2*(le+br)
print("perimeter of rectangle: ",peri)
# Write a program to calculate the area of square
side=int(input("Enter Side"))
area=side*side
print("area of square: ",area)
# Write a program to calculate the perimeter of square
side=int(input("Enter Side"))
peri=4*side
print("perimeter of square: ",peri)
# Write a program to calculate the area of triangle
base=float(input("Enter Base"))
height=float(input("Enter Height"))
area=0.5*base*height
print("area of triangle: ",area)
# Write a program to calculate the temperature from Fahrenheit
to Celsius
ce=float(input("Enter Temperature in Celsius"))
fa=(ce*1.8)+32
print("Temperature in Fahrenheit ",fa)
# Write a program to calculate the temperature from Celsius to
Fahrenheit
fa=float(input("Enter Temperature in Fahrenheit"))
ce=(fa-32)/1.8
print ("Temperature in Celsius ",ce)
# Write a program to enter your name
first=input("Enter your first name")
last=input("Enter your last name")
full=first+" "+last
print("Your full name ",full)
# Write a program to check whether the number is even or odd
no=int(input("Enter No"))
if(no%2==0):
print(no," is even no")
else:
print(no," is odd no")
# Write a program to check if no is completely divisible by 2
then print the square otherwise print cube
no=int(input("Enter No"))
if(no%2==0):
res=no*no
print("Result ",res)
else:
res=no*no*no
print("Result ",res)
# Write a program to enter percentage and print the message
"Certificate of Excellence" if the student gets more than 80%
per=int(input("Enter No"))
if(per>80):
print("Congratulations")
print("You are awarded with certificate of excellence")
# Write a program to enter percentage and print the message
"Certificate of Excellence" if the student gets more than 80%
otherwise print the message score more than 80%
per=int(input("Enter No"))
if(per>80):
print("Congratulations")
print("You are awarded with certificate of excellence")
else:
print("score more than 80%")