Category: Other

python tutorials and learn python

Created with Sketch.

Python program that uses nested loops to transpose a given matrix

Python program that uses nested loops to transpose a given matrix The function transpose_matrix(matrix) takes a 2D matrix as an argument. It first determines the number of rows and columns of the matrix using the len() function. Then it creates a new 2D matrix with the number of rows and columns swapped, using list comprehension,…
Read more

Python program that uses nested loops to multiply two matrices:

Python program that uses nested loops to multiply two matrices: The function multiply_matrices(A, B) takes two 2D matrices A and B as arguments. It first determines the number of rows and columns of the matrices using the len() function. Then it creates a new 2D matrix C with rows of the first matrix and columns…
Read more

Python program that uses nested loops to add two matrices of the same size

Python program that uses nested loops to add two matrices of the same size The function add_matrices(A, B) takes two 2D matrices A and B as arguments. It first determines the number of rows and columns of the matrices using the len() function. Then it creates a new 2D matrix C of the same size,…
Read more

Python program that uses recursion to find the factorial of a given number:

Python Program: Recursion to Find Factorial Recursion is a powerful programming concept where a function calls itself, and it’s often used to solve problems that can be broken down into smaller, identical subproblems. In this blog post, we’ll explore a Python program that uses recursion to find the factorial of a given number. The post…
Read more

Python program that uses recursion to display the Fibonacci sequence up to a given number:

Python program that uses recursion to display the Fibonacci sequence up to a given number: The fibonacci() function takes a single argument, n, which represents the number of terms in the sequence to be displayed. The function uses recursion to calculate the terms of the Fibonacci sequence. The base case for the recursion is when…
Read more

Python program that uses the built-in calendar module to display a calendar for a given year:

python program that uses the built-in calendar module to display a calendar for a given year: The calendar.calendar() function takes a single argument, the year for which to display the calendar, and returns a string representation of the calendar for that year. The input() function is used to prompt the user to enter a year,…
Read more

Python program that makes a simple calculator:

Python program that makes a simple calculator: This program defines a function calculator() that takes an operator and two numbers as arguments. The function uses an if-elif statement to check the operator and perform the appropriate arithmetic operation on the two numbers and return the result. The program then prompts the user to enter two…
Read more

Python program that finds the ASCII value of a given character:

python program that finds the ASCII value of a given character: The program prompts the user to enter a character using the input() function, and stores the value in the variable “character”. It then uses the built-in function ord() to find the ASCII value of the character. The ord() function returns an integer representing the…
Read more

Python program that converts a given decimal number to binary, octal and hexadecimal:

Python program that converts a given decimal number to binary, octal and hexadecimal: The program prompts the user to enter a decimal number using the input() function, and stores the value in the variable “decimal”. Then it uses the built-in functions bin(), oct() and hex() to convert the decimal number to binary, octal and hexadecimal…
Read more

Python program that finds the highest common factor (HCF) of two given numbers:

Python program that finds the highest common factor (HCF) of two given numbers: The program prompts the user to enter two numbers using the input() function, and stores the values in the variables “num1” and “num2”. It then uses an if-else statement to find the smaller number out of the two numbers. Then it uses…
Read more