0% found this document useful (0 votes)
9 views16 pages

Class 9 Python Practical File

This document is a Python practical file for Class IX students, containing various programming exercises. Each program includes an aim, algorithm, code, and expected output, covering topics such as basic input/output, arithmetic operations, control structures, and list manipulation. The exercises range from printing 'Hello World' to checking for palindromes and counting vowels in a string.
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)
9 views16 pages

Class 9 Python Practical File

This document is a Python practical file for Class IX students, containing various programming exercises. Each program includes an aim, algorithm, code, and expected output, covering topics such as basic input/output, arithmetic operations, control structures, and list manipulation. The exercises range from printing 'Hello World' to checking for palindromes and counting vowels in a string.
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

CLASS IX - ARTIFICIAL INTELLIGENCE

PYTHON PRACTICAL FILE


Name: ____________________

Class & Section: ____________________

Roll No: ____________________

Subject Teacher: ____________________


Program 1: Hello World
Aim: To print Hello World.

Algorithm:
1. Start
2. Print 'Hello World'
3. Stop

Program:
print('Hello World')

Output:
Hello World
Program 2: Addition of Two Numbers
Aim: To add two numbers.

Algorithm:
1. Start
2. Input two numbers
3. Add them
4. Display result
5. Stop

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

Output:
Enter first number: 5
Enter second number: 3
Sum = 8
Program 3: Area of Circle
Aim: To calculate area of a circle.

Algorithm:
1. Start
2. Input radius
3. Calculate area = 3.14*r*r
4. Print area
5. Stop

Program:
r=float(input('Enter radius: '))
area=3.14*r*r
print('Area =',area)

Output:
Enter radius: 2
Area = 12.56
Program 4: Even or Odd
Aim: To check whether a number is even or odd.

Algorithm:
1. Start
2. Input number
3. If number%2==0 print Even else Odd
4. Stop

Program:
num=int(input('Enter number: '))
if num%2==0:
print('Even')
else:
print('Odd')

Output:
Enter number: 4
Even
Program 5: Largest of Three Numbers
Aim: To find largest of three numbers.

Algorithm:
1. Start
2. Input three numbers
3. Compare using if-elif-else
4. Print largest
5. Stop

Program:
a=int(input())
b=int(input())
c=int(input())
if a>b and a>c:
print(a)
elif b>c:
print(b)
else:
print(c)

Output:
5
9
3
9
Program 6: Leap Year
Aim: To check leap year.

Algorithm:
1. Start
2. Input year
3. Check leap condition
4. Print result
5. Stop

Program:
y=int(input('Enter year: '))
if (y%4==0 and y%100!=0) or y%400==0:
print('Leap Year')
else:
print('Not Leap Year')

Output:
Enter year: 2024
Leap Year
Program 7: Print 1 to 10
Aim: To print numbers from 1 to 10.

Algorithm:
1. Start
2. Use for loop range(1,11)
3. Print numbers
4. Stop

Program:
for i in range(1,11):
print(i)

Output:
1
2
3
4
5
6
7
8
9
10
Program 8: Multiplication Table
Aim: To print multiplication table.

Algorithm:
1. Start
2. Input number
3. Use loop from 1 to 10
4. Print table
5. Stop

Program:
n=int(input('Enter number: '))
for i in range(1,11):
print(n,'x',i,'=',n*i)

Output:
Enter number: 2
2x1=2
...
2 x 10 = 20
Program 9: Factorial
Aim: To find factorial of a number.

Algorithm:
1. Start
2. Input number
3. Use loop multiply
4. Print factorial
5. Stop

Program:
n=int(input())
fact=1
for i in range(1,n+1):
fact*=i
print('Factorial=',fact)

Output:
5
Factorial= 120
Program 10: Sum of N Natural Numbers
Aim: To find sum of first N numbers.

Algorithm:
1. Start
2. Input n
3. Loop from 1 to n
4. Add numbers
5. Print sum
6. Stop

Program:
n=int(input())
total=0
for i in range(1,n+1):
total+=i
print('Sum=',total)

Output:
5
Sum= 15
Program 11: Reverse a Number
Aim: To reverse a number.

Algorithm:
1. Start
2. Input number
3. Use while loop
4. Reverse digits
5. Print result
6. Stop

Program:
n=int(input())
rev=0
while n>0:
d=n%10
rev=rev*10+d
n//=10
print('Reverse=',rev)

Output:
123
Reverse= 321
Program 12: Palindrome Number
Aim: To check palindrome number.

Algorithm:
1. Start
2. Input number
3. Reverse it
4. Compare
5. Print result
6. Stop

Program:
n=int(input())
orig=n
rev=0
while n>0:
d=n%10
rev=rev*10+d
n//=10
if orig==rev:
print('Palindrome')
else:
print('Not Palindrome')

Output:
121
Palindrome
Program 13: Count Vowels
Aim: To count vowels in a string.

Algorithm:
1. Start
2. Input string
3. Loop through characters
4. Count vowels
5. Print count
6. Stop

Program:
s=input()
count=0
for ch in s:
if [Link]() in 'aeiou':
count+=1
print('Vowels=',count)

Output:
Hello
Vowels= 2
Program 14: Display List Elements
Aim: To display elements of a list.

Algorithm:
1. Start
2. Create list
3. Use loop
4. Print elements
5. Stop

Program:
nums=[10,20,30,40]
for i in nums:
print(i)

Output:
10
20
30
40
Program 15: Maximum in a List
Aim: To find maximum number in list.

Algorithm:
1. Start
2. Create list
3. Compare elements
4. Print maximum
5. Stop

Program:
nums=[5,9,2,7]
maxi=nums[0]
for i in nums:
if i>maxi:
maxi=i
print('Maximum=',maxi)

Output:
Maximum= 9

You might also like