Interactive Code Snippets

Code examples for - Page 4

Run, edit, and experiment with ready-to-use code algorithms and utilities right in your browser.

Showing 24 templates
python

Validate Iranian Mobile Numbers with Regex in Python

Learn how to validate Iranian mobile phone numbers using regex in Python. This snippet checks the 11-digit format starting with 09.

Run
python

Python Prime Number Checker - Simple Code

A simple Python function to check if a number is prime, using square root optimization. Includes examples.

Run
python

Prime Number Checker in Python - Simple Function

Learn how to check if a number is prime in Python with this simple divisor-counting function. Includes examples for 5, 12, 37, 93, 1567.

Run
python

Python strftime: Format Dates and Times

Learn how to use Python's strftime method to format datetime objects into various strings. Covers common format codes with examples.

Run
python

Calculate Date Difference with datetime in Python

Learn how to calculate the number of days between two dates in Python using datetime and display the day difference.

Run
python

NumPy sqrt: How to Calculate Square Roots in Python

Learn how to calculate the square root of NumPy array elements using np.sqrt. Simple code example for Python.

Run
python

Python List Slicing with map and lambda

Learn how to extract substrings from a list in Python using map and lambda. Simple code to slice strings after a specific index.

Run
python

Python Slicing: Extract Names from Strings with Numbers

Learn how to extract names from strings like '4533-ali' using Python slicing. A simple list comprehension example.

Run
python

Convert List to String Using reduce in Python

Learn how to convert a Python list to a string using reduce and lambda. Efficient technique with step-by-step explanation.

Run
python

Convert List to String in Python Using join()

Learn how to convert a list to a string in Python using the join() method with simple examples.

Run
C++

C++ Exception Handling Example: Throw and Catch Age Validation

Learn C++ exception handling with a simple age check. Code demonstrates throw and catch to restrict access for users under 18.

Run
C++

Const Variables in C++

Learn about const variables in C++, how to define them, and why modifying them causes a compile-time error.

Run
Java

Java Sum and Product of Array Elements Example

Learn how to calculate the sum and product of an integer array in Java with this simple MyClass example.

Run
Java

Java 2D Array Example - Accessing Elements (With Code)

Learn how to create and access elements in a 2D array with a simple Java example. See the output and understand array indexing.

Run
Java

Java Switch Statement Example: Difficulty Levels

Learn how to use Java switch to map levels to difficulty strings. Simple code example.

Run
Java

Java String Concatenation Example using concat()

Learn how to use Java's String.concat() method to join two strings. Simple code example with output.

Run
Java

Java String indexOf() Example: Find Substring Position

Learn how to use Java's String indexOf() method to locate a substring. Example code with output and detailed explanation.

Run
Java

Java String toUpperCase() and toLowerCase() Example

Learn how to convert strings to uppercase and lowercase in Java with simple examples. Perfect for beginners.

Run
python

Python Falsy Values: Complete Guide

Learn about Python falsy values: False, None, 0, empty strings, tuples, lists, and dicts. See examples and how to use them in conditionals.

Run
python

Python Script to Calculate Student Average Grade

A simple Python program that takes grades for school subjects, validates them, and computes the average. Perfect for beginners.

Run
python

Calculate Average Grade with Course List in Python

Learn to create a Python program that calculates the average grade from course scores using loops and lists.

Run
python

Python if-else Example: Check Average Score

Learn Python if-else with a simple average score example. Get passed or failed output based on user input.

Run
python

Python if Statement: Pass/Fail Based on Average

Learn how to use a simple if statement in Python to check if an average score is above 10 and print a success message.

Run
python

Python Type Casting: Convert String to Integer with input()

Learn how to convert user input from string to integer in Python using int() and perform arithmetic operations. Simple example included.

Run