Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

Python programmes grade 9

The document outlines various Python programs, including those for printing personal information, calculating total and average marks, generating multiplication tables, and managing lists. Each program is accompanied by its aim, algorithm, and expected results, demonstrating basic programming concepts and arithmetic operations. The content serves as a guide for beginners to understand and implement simple Python functionalities.

Uploaded by

swetha.prak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Python programmes grade 9

The document outlines various Python programs, including those for printing personal information, calculating total and average marks, generating multiplication tables, and managing lists. Each program is accompanied by its aim, algorithm, and expected results, demonstrating basic programming concepts and arithmetic operations. The content serves as a guide for beginners to understand and implement simple Python functionalities.

Uploaded by

swetha.prak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Print Personal Information of a Student # Personal Information

AIM: student_name = "YOUR NAME"

fathers_name = "YOUR FATHER NAME"


To create a Python program that prints personal information including a student’s
name, father’s name, class, and school name in a formatted manner. student_class = “9th Grade"

school_name = "Vishwa Sishya Vidyodaya School"


ALGORITHM:
# Print Personal Information
1. Start python
2. Define Variables: print("Student Name: ", student_name)

o Assign the student's name to a variable (e.g., student_name). print("Father's Name: ", fathers_name)
o Assign the father’s name to a variable (e.g., fathers_name).
print("Class: ", student_class)
o Assign the class to a variable (e.g., student_class).
print("School Name: ", school_name)
o Assign the school name to a variable (e.g., school_name).
3. Print Information:
o Use the print() function to display each piece of information with
appropriate labels (e.g., "Student Name:", "Father's Name:", etc.).
4. End

RESULT:

The Python program successfully prints the personal information, including the
student's name, father's name, class, and school name, in a clear and formatted
manner.

2.Print Given Pattern Using Multiple Print Commands

AIM:
PROGRAM:
To create a Python program that prints given patterns using multiple print() ALGORITHM:
commands.
1. Start python
ALGORITHM: 2. Input Marks:
o Prompt the user to input marks for 5 subjects and store them in
1. Start python
separate variables.
2. Use multiple print() commands to display a given pattern with increasing
3. Calculate Total:
and decreasing numbers of asterisks (*).
o Add the marks of all 5 subjects to calculate the total marks.
3. End
4. Calculate Average:
PROGRAM o Divide the total marks by 5 to calculate the average marks.
5. Print Results:
print("* *****")
o Display the total marks.
print("** ****") o Display the average marks.
6. End
print("*** ***")

print("**** **")

print("***** *")

RESULT:

The Python program successfully prints the given pattern using multiple print()
commands:
Program

# Input Marks
3.Calculate the Total and Average Marks subject1 = float(input("Enter marks for Subject 1: "))

AIM: subject2 = float(input("Enter marks for Subject 2: "))

To create a Python program that calculates the total and average marks obtained subject3 = float(input("Enter marks for Subject 3: "))

in 5 subjects. subject4 = float(input("Enter marks for Subject 4: "))


subject5 = float(input("Enter marks for Subject 5: ")) 3. Prompt the user to input the second number and store it in the variable
num2.
# Calculate Total
4. Calculate the sum of num1 and num2 and store the result in the variable
total_marks = subject1 + subject2 + subject3 + subject4 + subject5
sum_result.
# Calculate Average 5. Display the sum in a formatted message.

average_marks = total_marks / 5 6. Stop

# Print Results Program

print("Total Marks: ", total_marks) num1 = float(input("Enter the first number: "))
print("Average Marks: ", average_marks)
num2 = float(input("Enter the second number: "))
# End
sum_result = num1 + num2
RESULT:
print(f"The sum of {num1} and {num2} is: {sum_result}")
The Python program successfully calculates the total and average marks based on
the input provided for 5 subjects. The program outputs the correct total and Result

average marks, demonstrating the effective use of basic arithmetic operations in The Python program successfully prompts the user for two numbers, then
Python. calculates and displays the correct sum of the entered numbers.

5.MULTIPLICATION TABLE
4.To print the sum of two numbers using input statement.
AIM:
Aim
To create a Python program that prints the multiplication table of user input up to
To develop a Python program that accepts two numbers as input from the user, 10 terms.
calculates their sum, and displays the result.
ALGORITHM:
Algorithm
1. Start
1. Start 2. Input:
2. Prompt the user to input the first number and store it in the variable num1.
Read an integer input from the user and store it in a variable called
multiplier.

3. For Loop:
 Initialize a loop variable i starting from 1 up to 10 (inclusive).
 Inside the loop:

 Compute the result of multiplier * i.


 Print the formatted string displaying the multiplication table entry.
4. End

Program

multiplier = int(input("Enter the table number "))

for i in range(1, 11):

result = multiplier * i

print(f"{multiplier} x {i} = {result}")


6.Calculate the Surface Area and Volume of a Cuboid

AIM:
RESULT:
To create a Python program that calculates the surface area and volume of a
The Python program successfully prints the multiplication table of 5 up to 10
cuboid given its length, width, and height.
terms, displaying the output
ALGORITHM:

1. Start python
2. Input Dimensions:
o Prompt the user to input the length, width, and height of the cuboid.
3. Calculate Surface Area:
o Use the formula: # 4. Calculate Volume
o surface area = 2(𝒍𝒘 + 𝒘𝒉 + 𝒍𝒉).
volume = length * width * height
4. Calculate Volume:
o Use the formula: # 5. Print Results print("Surface Area of the Cuboid: ", surface_area)
o V=l×w×h
print("Volume of the Cuboid: ", volume)
5. Print Results:
o Display the calculated surface area. # 6. End
o Display the calculated volume.
RESULT:
6. End
The Python program successfully calculates and prints the surface area and
volume of a cuboid based on the user-provided dimensions. The results are
displayed correctly, demonstrating the effective use of mathematical formulas in
Python.

7.Manage a List of Children for a Science Quiz


Program
AIM:
#1 Start python
To manage a list of children selected for a science quiz by performing specific
#2 Input Dimensions operations: printing the list, deleting a name, adding a new name, and removing

length = float(input("Enter the length of the cuboid: ")) an item from a specific position.

width = float(input("Enter the width of the cuboid: ")) ALGORITHM:

height = float(input("Enter the height of the cuboid: ")) 1. Start python


2. Create List:
# 3. Calculate Surface Area o Define a list with the names of the children: ['Arjun', 'Sonakshi',

surface_area = 2 * (length * width + width * height + height * length) 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik'].
3. Print Whole List:
o Use the print() function to display the entire list. # 7. Print Updated List
4. Delete Name "Vikram":
print("Updated List:", children)
o Use the remove() method to delete the name "Vikram" from the list.
# 8. End
5. Add Name "Jay" at the End:
o Use the append() method to add "Jay" at the end of the list. RESULT:
6. Remove Item at the Second Position: The Python program successfully performs the following operations:
o Use the pop() method with the index 1 to remove the item at the
Prints the Original List:
second position in the list.
7. Print Updated List: Deletes the Name "Vikram":

o Use the print() function to display the updated list. Adds the Name "Jay" at the End:
8. End
Removes the Item at the Second Position:

8.Operations on a List of Numbers

program AIM:
# 1. Start python
To perform operations on a list of numbers including printing the length of the
# 2. Create List
list, printing elements from specific positions using positive indexing, and
children = ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik'] printing elements using negative indexing.
# 3. Print Whole List
ALGORITHM:
print("Original List:", children)
1. Start python
# 4. Delete Name "Vikram"
2. Create List:
children.remove('Vikram') o Define a list num with elements [23, 12, 5, 9, 65, 44].

# 5. Add Name "Jay" at the End 3. Print Length of List:


o Use the len() function to get and print the length of the list.
children.append('Jay')
4. Print Elements from Second to Fourth Position Using Positive
# 6. Remove Item at the Second Position Indexing:
children.pop(1) o Slice the list from index 1 to index 4 (inclusive) and print the result.
5. Print Elements from Third to Fifth Position Using Negative Indexing:
o Slice the list using negative indexing from -4 to -1 (inclusive) and
print the result.
6. End RESULT:

The Python program successfully performs the following operations:

Prints the Length of the List:

Prints Elements from Second to Fourth Position Using Positive Indexing:

Prints Elements from Third to Fifth Position Using Negative Indexing:

9. Age Verification System


program
Aim
# 1. Start python
To write a Python program that calculates a person's age based on their birth year
# 2. Create List
and the current year, and determines if they are eligible (18 years or older).
num = [23, 12, 5, 9, 65, 44]

# 3. Print Length of List

print("Length of the list:", len(num)) Algorithm

# 4. Print Elements from Second to Fourth Position Using Positive Indexing 1. Start
2. Prompt the user to enter their birth year and store it in the variable
print("Elements from second to fourth position:", num[1:4])
birth_year.
# 5. Print Elements from Third to Fifth Position Using Negative Indexing
3. Prompt the user to enter the current year and store it in the variable
print("Elements from third to fifth position using negative indexing:", num[-4:- current_year.
1]) 4. Calculate the age using the formula:

# 6. End age=current_year−birth_year\text{age} = \text{current\_year} -


\text{birth\_year}age=current_year−birth_year
5. Check if the calculated age is negative:
o If yes, print "Invalid birth year. Age cannot be negative." Result
6. Check if the calculated age is 18 or older:
The program will:
o If yes, print "You are {age} years old. You are eligible."
7. If the calculated age is less than 18: 1. Accept the user's birth year and current year.
o Print "You are {age} years old. You are not eligible." 2. Calculate their age.
8. Stop 3. Print one of the following messages based on their age:
o "Invalid birth year. Age cannot be negative."
o "You are {age} years old. You are eligible."
o "You are {age} years old. You are not eligible."

10. SIMPLE MATH CALCULATOR


program
Aim
# Input: Ask the user for their birth year and current year
To create a Python program that performs basic arithmetic operations (+, -, *, /)
birth_year = int(input("Enter your birth year: ")) based on user input.
current_year = int(input("Enter the current year: "))
Algorithm
# Calculate age
1. Start
age = current_year - birth_year 2. Input: Get the first number (num1).
# Check age validity and eligibility 3. Input: Get the second number (num2).
4. Input: Ask the user to choose an operation (+, -, *, /).
if age < 0:
5. Perform Operation:
print("Invalid birth year. Age cannot be negative.")
 If the operation is +, add the two numbers and display the result.
if age >= 18:
 If the operation is -, subtract the second number from the first and
print(f"You are {age} years old. You are eligible.")
display the result.
if age < 18:  If the operation is *, multiply the two numbers and display the result.

print(f"You are {age} years old. You are not eligible.")  If the operation is /, check:
o If the second number is not zero, divide the first number by the result = num1 / num2
second and display the result. print(f"The result is: {result}")
o Otherwise, display an error: "Division by zero is not allowed." else:
 If the operation is invalid, display: "Invalid operation." print("Error: Division by zero is not allowed.")
else:
6. End
print("Invalid operation. Please choose +, -, *, or /.")

Result
Program
The program will:
# Input: Ask the user for two numbers
num1 = float(input("Enter the first number: ")) 1. Accept two numbers from the user.
num2 = float(input("Enter the second number: ")) 2. Allow the user to choose an arithmetic operation (+, -, *, /).
# Input: Ask the user to choose an operation 3. Perform the chosen operation and display the result.
print("Choose an operation: +, -, *, /") 4. Handle division by zero and invalid operation inputs gracefully.
operation = input("Enter the operation: ")
# Perform the calculation and display the result
if operation == '+':
result = num1 + num2
print(f"The result is: {result}")
elif operation == '-':
result = num1 - num2
print(f"The result is: {result}")
elif operation == '*':
result = num1 * num2
print(f"The result is: {result}")
elif operation == '/':
if num2 != 0:

You might also like