Blog

python tutorials and learn python

Created with Sketch.

Python program that creates a circular linked list and displays its elements:

Python program that creates a circular linked list and displays its elements: In this example, we first define a Node class with a constructor that initializes the data and next properties. The CircularLinkedList class is implemented using the Node class. The CircularLinkedList class has an append method that adds new data to the end of…
Read more

Python program that creates a circular linked list of n nodes and displays it in reverse order:

Python program that creates a circular linked list of n nodes and displays it in reverse order: In this example, we first define a Node class with a constructor that initializes the data and next properties. The CircularLinkedList class is implemented using the Node class. The CircularLinkedList class has an append method that adds new…
Read more

Python program that creates a circular linked list of N nodes and counts the number of nodes:

A circular linked list is a type of linked list where the last node points to the first node, forming a circular loop. Here is a Python program that creates a circular linked list of N nodes and counts the number of nodes in the list: In this example, we first define a Node class…
Read more

Python program that uses a for loop and an if statement to print all pronic numbers between 1 and 100:

A pronic number is a number that is the product of two consecutive integers. For example, the number 6 is a pronic number because it is the product of 2 and 3 (2 x 3 = 6). Here is a Python program that uses a for loop and an if statement to print all pronic…
Read more

Python program that uses the modulus operator and the sum() function to check if a given number is a Harshad number

Python program that uses the modulus operator and the sum() function to check if a given number is a Harshad number The function is_harshad(n) takes an integer as an argument, it uses the str(n) method to convert the number to a string, and then the split() method to split the string into a list of…
Read more

Python program that uses a for loop and the is_happy() function to print all happy numbers between 1 and 100:

Python program that uses a for loop and the is_happy() function to print all happy numbers between 1 and 100: This program uses a for loop to iterate over the range 1 to 100, and for each number, it checks if it is a happy number by calling the is_happy(n) function. If the function returns…
Read more

Python program that uses a while loop and the split() method to check if a given number is a happy number:

A happy number is a number that eventually reaches 1 when replaced by the sum of the squares of its digits in a process called digit-square-sum. For example, the number 7 is a happy number because 7 -> 49 -> 97 -> 130 -> 10 -> 1. Here is a Python program that uses a…
Read more

Python program that uses a for loop and the is_disarium() function to print all Disarium numbers between 1 to 100:

Python program that uses a for loop and the is_disarium() function to print all Disarium numbers between 1 to 100:   This program uses a for loop to iterate over the range 1 to 100, and for each number, it checks if it is a Disarium number by calling the is_disarium(n) function. If the function…
Read more

Python program that uses a for loop and the pow() function to check if a given number is a Disarium number:

A Disarium number is a number such that the sum of its digits powered with its corresponding position is equal to the number itself. For example, the number 89 is a Disarium number because 8^1 + 9^2 = 89. Here is a Python program that uses a for loop and the pow() function to check…
Read more

Python program that uses the sort() method and the reverse argument to sort the elements of an array in descending order:

Python program that uses the sort() method and the reverse argument to sort the elements of an array in descending order: The function sort_descending(arr) takes an array as an argument. It uses the sort() method with the reverse argument set to True to sort the elements of the array in descending order. The function returns…
Read more