How to Reverse a Number in Python

The following python program reverses a given multi-digit number. In this example, we simply print the digits in reverse order without removing redundant zeros. For example, if the input number is "1000", the reversed number displayed will be "0001" instead of "1". number = int(input("Enter a number: ")) reverse_number = ” while number > 0: […]

Python Program to Draw a Square and Chess Board Using Turtle

For simple drawing, python provides a built-in module named turtle. This behaves like a drawing board and you can use various drawing commands to draw over it. The basic commands control the movement of the drawing pen itself. We start with a very basic drawing program and work our way through to draw a complete […]

How to Generate Cryptographically Secure Random Numbers in Python

Generating a cryptographically secure random number is very easy in python 3.6 and above. You can use the new secrets module and the function randbelow() for it. This function returns a random number below the specified value. The following python 3.6+ program demonstrates the use of secrets module for secure random numbers, import secrets # […]

Python Program to Check for Armstrong Number

What is an Armstrong number? An Armstrong number is an n-digit number such that the sum of it digits raised to the power n is the number itself. For example, 153 is a 3 digit Armstrong number since, 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 Another example […]

How to Check Whether a String is a Palindrome Using Python

Checking for a palindrome string in python is trivial due to built-in functions and powerful string indexing and slicing. The following python program checks whether a string input by user is a palindrome, input_str = input("Please enter a string: ").lower() if input_str == input_str[::-1]: print("{} is a palindrome".format(input_str)) else: print("{} is NOT a palindrome".format(input_str)) Even […]