Skip to main content

Posts

Showing posts from 2024

6 Python Examples using bit manipulation for beginners

Numbers are represented using bits internally in computers, each bit can contain a boolean value 0 or 1 i.e., whether the bit is set or not. Bit manipulation is a concept where the individual bits within a given number are modified and/or looked at. There are quite a few cases where bit manipulation provides effective coding while consuming less memory. While bit manipulation is very popular in languages like C/C++, the article highlights some usage of bit manipulation using beginner-friendly examples.

10 Programs using numbers for Python beginners

Numbers are at the core of learning any programming language. From basic arithmetic operations to complex computations, numbers are everywhere in programming. Having a strong foundation on numbers and arithmetic would come a long way in mastering any programming language. In this article, ten basic Python programs that involve numbers and arithmetic are explored.

Simple arithmetic expression evaluator in Python

Taking user input for two variables, an arithmetic operator and computing the results is very basic. This article projects a fresh look at extending the simple calculator by evaluating complex arithmetic expressions input by the user while also providing a mechanism to include the last computed value in a follow-up expression. All of these in only a few lines of code, by exploiting the Python's eval function.

Implementing Monotonic Stack in Python

A monotonic stack is an extension of the Stack data structure in which the elements of the stack are in either increasing or decreasing order. The stack in which the items are in increasing order is called the monotonically increasing stack, the top element of such a stack will be the largest of all the elements below. On the other hand, if the items are arranged in a decreasing order then the stack is called a monotonically decreasing stack, on which the top element will be the smallest of all the elements below. Monotonic stacks are very popular in competitive programming.