0% found this document useful (0 votes)
2 views

Python Prgs for record class 9th

The document contains various Python programs for Class IX, demonstrating the use of print statements, input statements, and control structures like if, for, and while. It includes algorithms and flowcharts for tasks such as printing personal information, calculating squares, sums, areas, and checking eligibility for voting. Each program is accompanied by sample outputs to illustrate functionality.

Uploaded by

rituprana9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Prgs for record class 9th

The document contains various Python programs for Class IX, demonstrating the use of print statements, input statements, and control structures like if, for, and while. It includes algorithms and flowcharts for tasks such as printing personal information, calculating squares, sums, areas, and checking eligibility for voting. Each program is accompanied by sample outputs to illustrate functionality.

Uploaded by

rituprana9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CLASS IX

PYTHON PROGRAMS

USING PRINT STATEMENT


 To print personal information like Name, Father’s Name, Class, School Name.
Flowchart:

# Personal Information
name = "John Doe"
f_name = "Michael Doe"
c_name = "10th Grade"
s_name = "Springfield High School"
# Print the information
print("Personal Information:")
print("Name:", name)
print("Father's Name:", f_name)
print("Class:", c_name)
print("School Name:", s_name)

O/P: Personal Information:


Name: John Doe
Father's Name: Michael Doe
Class: 10th Grade
School Name: Springfield High School
Algorithm to Print Personal Information
1. Start
2. Declare variables:
o name for storing the person's name.
o f_name for storing the father's name.
o c_name for storing the class name.
o s_name for storing the school name.
3. Initialize variables with respective values:
o name = "John Doe"
o f_name = "Michael Doe"
o c_name = "10th Grade"
o s_name = "Springfield High School"
4. Print header: Display "Personal Information:"
5. Print each detail:
o Display "Name:" followed by the value of name.
o Display "Father's Name:" followed by the value of f_name.
o Display "Class:" followed by the value of c_name.
o Display "School Name:" followed by the value of s_name.
6. End
------------------------------------------------------------------------------------------------------------
● To find square of number 7
Flowchart:
# Number to be squared
number = 7
# Calculate the square
square = number ** 2
# Print the result
print("The square of", number, "is:", square)

O/P: The square of 7 is: 49


Algorithm to Calculate and Print the Square of a Number
1. Start
2. Initialize a variable:
o number with the value 7.
3. Calculate the square:
o Compute square as number ** 2.
4. Print the result:
o Display the message: "The square of [number] is: [square]".
5. End

------------------------------------------------------------------------------------------------------------
● To find the sum of two numbers 15 and 20.
Flowchart:
# Define the numbers
num1 = 15
num2 = 20
# Calculate the sum
sum_result = num1 + num2
# Print the result
print("The sum of", num1, "and", num2, "is:", sum_result)

O/P: The sum of 15 and 20 is: 35

Algorithm to Calculate and Print the Sum of Two Numbers


1. Start
2. Initialize two variables:
o num1 with the value 15.
o num2 with the value 20.
3. Calculate the sum:
o Compute sum_result as num1 + num2.
4. Print the result:
o Display the message: "The sum of [num1] and [num2] is: [sum_result]".
5. End
------------------------------------------------------------------------------------------------------------
● To convert length given in kilometers into meters.
# Input length in kilometers
kilometers = float(input("Enter length in kilometers: "))
# Convert kilometers to meters
meters = kilometers * 1000
# Print the result
print(f"{kilometers} kilometers is equal to {meters} meters.")

O/P: Enter length in kilometers: 2.5


2.5 kilometers is equal to 2500.0 meters.
------------------------------------------------------------------------------------------------------------
● To print the table of 5 up to five terms.
# Define the number for the table
number = 5
# Print the table up to five terms
for i in range(1, 6):
result = number * i
print(f"{number} x {i} = {result}")

O/P: 5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
------------------------------------------------------------------------------------------------------------
● To calculate Simple Interest if the principle_amount = 2000 rate_of_interest = 4.5 time = 10
# Define the values
principle_amount = 2000
rate_of_interest = 4.5
time = 10
# Calculate Simple Interest
simple_interest = (principle_amount * rate_of_interest * time) / 100
# Print the result
print("The Simple Interest is:", simple_interest)

O/P: The Simple Interest is: 900.0


------------------------------------------------------------------------------------------------------------
USING INPUT STATEMENT
● To calculate Area and Perimeter of a rectangle
# Get the length and width of the rectangle from the user
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
# Calculate area and perimeter
area = length * width perimeter = 2 * (length + width)
# Print the results
print("The Area of the rectangle is:", area)
print("The Perimeter of the rectangle is:", perimeter)

O/P: Enter the length of the rectangle: 5


Enter the width of the rectangle: 3
The Area of the rectangle is: 15.0
The Perimeter of the rectangle is: 16.0
------------------------------------------------------------------------------------------------------------
● To calculate Area of a triangle with Base and Height
# Get the base and height of the triangle from the user
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
# Calculate the area
area = 0.5 * base * height
# Print the result
print("The Area of the triangle is:", area)

O/P: Enter the base of the triangle: 4


Enter the height of the triangle: 5
The Area of the triangle is: 10.0
------------------------------------------------------------------------------------------------------------
● To calculating average marks of 3 subjects
# Get the marks for 3 subjects from the user
subject1 = float(input("Enter the marks for subject 1: "))
subject2 = float(input("Enter the marks for subject 2: "))
subject3 = float(input("Enter the marks for subject 3: "))
# Calculate the average
average_marks = (subject1 + subject2 + subject3) / 3
# Print the result
print("The average marks of the 3 subjects is:", average_marks)

O/P: Enter the marks for subject 1: 85


Enter the marks for subject 2: 90
Enter the marks for subject 3: 78
The average marks of the 3 subjects is: 84.33
------------------------------------------------------------------------------------------------------------
● To calculate discounted amount with discount %
# Get the original price and discount percentage from the user
original_price = float(input("Enter the original price: "))
discount_percent = float(input("Enter the discount percentage: "))
# Calculate the discounted amount
discount_amount = (original_price * discount_percent) / 100
# Calculate the final price after discount
final_price = original_price - discount_amount
# Print the results
print("The discounted amount is:", discount_amount)
print("The final price after discount is:", final_price)

O/P: Enter the original price: 1000


Enter the discount percentage: 20
The discounted amount is: 200.0
The final price after discount is: 800.0
------------------------------------------------------------------------------------------------------------
● To calculate Surface Area and Volume of a Cuboid
# Get the length, width, and height of the cuboid from the user
length = float(input("Enter the length of the cuboid: "))
width = float(input("Enter the width of the cuboid: "))
height = float(input("Enter the height of the cuboid: "))
# Calculate the surface area and volume
surface_area = 2 * (length * width + length * height + width * height)
volume = length * width * height
# Print the results
print("The Surface Area of the cuboid is:", surface_area)
print("The Volume of the cuboid is:", volume)
O/P: Enter the length of the cuboid: 5
Enter the width of the cuboid: 3
Enter the height of the cuboid: 4
The Surface Area of the cuboid is: 94.0
The Volume of the cuboid is: 60.0
------------------------------------------------------------------------------------------------------------
USING IF, FOR, WHILE STATEMENT
● Program to check if a person can vote
# Input the person's age
age = int(input("Enter your age: "))
# Check if the person is eligible to vote
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

O/P: Enter your age: 20


You are eligible to vote.
------------------------------------------------------------------------------------------------------------
● To check the grade of a student
# Input the student's marks
marks = float(input("Enter the marks of the student: "))
# Check the grade based on marks
if marks >= 90:
print("Grade: A")
elif marks >= 80:
print("Grade: B")
elif marks >= 70:
print("Grade: C")
elif marks >= 60:
print("Grade: D")
elif marks >= 50:
print("Grade: E")
else:
print("Grade: F")

O/P: Enter the marks of the student: 85


Grade: B
------------------------------------------------------------------------------------------------------------
● Input a number and check if the number is positive, negative or zero and display an
appropriate message
# Input a number
number = float(input("Enter a number: "))
# Check if the number is positive, negative, or zero
if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")
------------------------------------------------------------------------------------------------------------
● To print first 10 natural numbers
# Print first 10 natural numbers
for i in range(1, 11):
print(i)
O/P: 1
2
3
4
5
6
7
8
9
10
------------------------------------------------------------------------------------------------------------
● To print first 10 even numbers
# Print first 10 even numbers
for i in range(2, 21, 2):
print(i)
O/P: 2
4
6
8
10
12
14
16
18
20
------------------------------------------------------------------------------------------------------------
● To print odd numbers from 1 to n
# Input the value of n
n = int(input("Enter a number: "))
# Print odd numbers from 1 to n
for i in range(1, n+1, 2):
print(i)
------------------------------------------------------------------------------------------------------------
● To print sum of first 10 natural numbers
# Calculate sum of first 10 natural numbers using a loop sum_of_numbers = 0
for i in range(1, 11):
sum_of_numbers += i
print("The sum of the first 10 natural numbers is:", sum_of_numbers)

O/P: The sum of all numbers in the list is: 55

Note: Alternate program


# Sum of first 10 natural numbers
sum_of_numbers = sum(range(1, 11))
print("The sum of the first 10 natural numbers is:", sum_of_numbers)
------------------------------------------------------------------------------------------------------------
● Program to find the sum of all numbers stored in a list
# List of numbers
numbers = [10, 20, 30, 40, 50]
# Initialize sum variable
sum_of_numbers = 0
# Loop through the list and add each number to sum_of_numbers
for num in numbers:
sum_of_numbers += num
# Print the sum
print("The sum of all numbers in the list is:", sum_of_numbers)
O/P: The sum of all numbers in the list is: 150
------------------------------------------------------------------------------------------------------------

You might also like