BAL BHARTI
SCHOOL,
BAHADURGARH
PRACTICAL
FILE
CLASS IX
SUBJECT- ARTIFICIAL INTELLIGENCE
SUBMITTED TO: SUBMITTED BY:
________________________ ___________________________
______________________ ___________________
Python Programs
Note: Take all the input from the user in all the programs
1. Write a program in python to calculate the sum of 2 numbers.
2. Write a program to calculate the total and percentage of 5 subject marks (max marks =
20)
3. Write a program to print name, class, section, roll number and age in the given format:
Your name is ____
Your study in ___ class
Your roll number is _
Your age is ___ years
4. Write a program to check whether a number is negative, positive or zero
5. Write a program to print the table of a number using for loop
6. Write a program to swap 2 variables
7. Write a program to print even numbers between 1-10 including the numbers 1 and 10.
8. Write a program to create list.
9. Write a program to create list and reverse list
[Link] a program to display square, cube, floor division, modulus of any 2 given numbers
**************************************************************************************
Program 1. Write a program in python to calculate the sum of 2 numbers.
# Write a program in python to calculate the sum of 2 numbers.
a= int(input ("Enter first number"))
b= int(input("Enter second number"))
c= a+b
print ("Sum=", c)
Output:
Program 2. Write a program to calculate the total and percentage of 5 subject marks (max
marks = 20)
# Write a program to calculate the total and percentage of 5 subject marks (max marks =
20)
num1=int(input("Enter marks of subject 1 out of 20"))
num2=int(input("Enter marks of subject 2 out of 20"))
num3=int(input("Enter marks of subject 3 out of 20"'))
num4=int(input("Enter marks of subject 4 out of 20"'))
num5=int(input("Enter marks of subject 5 out of 20"))
total= num1+num2+num3+num4+num5
maximum_marks=5*20
percentage=(total/maximum_marks)*100
print("Total marks =", total, "out of" , maximum_marks)
print "Percentage=", percentage, "e")
Output:
Program 3. Write a program to print name, class, section, roll number and age in the given
format:
Your name is ____ Your study in ___ class Your roll number is _ Your age is ___ years
# Write a program to print name, class, section, roll number and age in the given format:
Your name is ____ Your study in ___ class Your roll number is _ Your age is ___ years
name=input("Enter your name")
clas=input("Enter your class")
section=input("Enter your section")
roll_number=input ("Enter your roll number")
age=input("Enter your age")
print("Your name is", name)
print("You study in", clas, "class")
print("Your roll number is", roll_number)
print("Your age is",age, "years")
Output:
Program 4. Write a program to check whether a number is negative, positive or zero
# Write a program to check whether a number is negative, positive or zero
num=int(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")
Output:
Program [Link] a program to print the table of a number using for loop
#Write a program to print the table of a number using for loop
num=int(input("Enter a
number"))
for i in range(1, 11):
print (num,"x", i, "=", num*i)
Output:
Program [Link] a program to swap 2 variables
# Write a program to swap 2 variables
a= input("Enter first value")
b= input("Enter second value")
value=a
a=b
b=value
print("After swapping")
print("First value =",a)
print("Second value=",b)
Output:
Program7. Write a program to print even numbers between 1-10 including the numbers 1
and 10.
# Write a program to print even numbers between 1-10 including the numbers 1 and 10.
for i in range (1,11):
if i% 2 = 0:
print(i)
Output:
[Link] a program to display square, cube, floor division, modulus of any 2 given
numbers
#Write a program to display square, cube, floor division, modulus of any 2 given numbers
a= int(input("Enter first number"))
b= int(input("Enter second number"))
print("Square", a**2, b**2)
print("Cube", a**3, b**3)
print("Floor division", a//b,b//a)
print ("Modulus", a%b, b%a)
Output:
******************************************************************************