Python programmes grade 9
Python programmes grade 9
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.
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: "))
To create a Python program that calculates the total and average marks obtained subject3 = float(input("Enter marks for Subject 3: "))
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:
Program
result = multiplier * i
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.
length = float(input("Enter the length of the cuboid: ")) an item from a specific position.
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:
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].
# 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:
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: