Author: mashiurrahman99
-
How to replace a character in a string with python
We will use replace method. for example our string is “ABC” We want to replace the C with D x=”ABC” x.replace(the character we want to replace, the character we want to place in the replacement) so it will be x.replace(“C”, “D”) The code x=”ABC” x=x.replace(“C”,”D”) print(x) Copy Code More string methods x=”Hello” x=x.lower() print(x) #hello…
-
Get the current script directory with python os module
Python os module is very helpful when need to go to a specific directory and create a directory. For example print out the current directory import os current_directory = os.getcwd() print(“Current Directory:”, current_directory) Copy Code More operating system-independent and navigate to a directory in a platform-independent way, mport os # Define the path relative to…
-
Create And Train Simple Artificial Neuron with python : Teach a Neuron to Sum two number
We will start this example with simplest neuron then train it to sum two number so it will be simple. And best part is for simplicity we will use only python standard library. We will write everything from scratch.. First the basics. Like our biological neuron artificial neuron can learn and change over time. Human…
-
How to find out perfect numbers with python
What is perfect Number?Perfect number is a positive integer number in which sum of divisors(proper divisors) is equal to itself Proper divisor the divisors of 10 is 1,2,5,10 Here 1,2,5 is proper divisor .. but 10 is not proper. because its the number we are divisioning There is a perfect number in 10 is 6…
-
Calculate time dilation with python
In this example imagine two object one is Earth And another object is traveling in the space \[ t_0 = t \sqrt{1 – \frac{v^2}{c^2}} \] t0: Represents the dilated time experienced by the object which is traveling or seems traveling from earth t: Time passed on earth v: Velocity of the traveling object. c: Speed…
-
How to convert text to sentence with python and nltk
We can easily convert text to sentence in python with nltk by tokenize sentence.. First install nltk Download nltk data . NLTK requires data files for tokenization. run the code in a python program to download the data. import nltk nltk.download(‘punkt’) Copy Code After download the necessary data from nltk import tokenize text=”In the symphony…
-
How to get all possible combinations with python
Python is rich with wonderful standard library so you do not have to write everything from the very beginning. With permutations from iterators we can get wonderful and useful result with less code >In this example code we get the user input as string > Get the user input length > Then run a for…
-
Easy Temperature Conversions with Python: A Beginner’s Guide (Celsius, Fahrenheit, Kelvin)
Basic Temperature Conversion Program This program takes a temperature input from the user, identifies the scale (Celsius, Fahrenheit, Kelvin), and converts it to the other two scales. Let’s break down the code step-by-step. For higher accuracy in the Kelvin scale use 273.15 instead of 273 x = str(input(“Enter in which scale you measured temperature (Celsius,…
-
How to get current time from browser in JavaScript
Current Time From Browser The current time is: We can get the current time with built- in JavaScript object Date To get the time we have to create the Date object first simply like this As we created the date object we can console.log to get the result We get the result like this. we…
-
Expiring Links Tutorial: Python Flask One-Time Link Generator
One time links are essential where users want to share resources with co-worker or friend’s effortlessly but at the same time restrict other from access. Its works best because the link automatically inactive if some one go to the link for the first time. That means the same link will not work for the second…