Category: Python
-
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,…
-
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…
-
Converting Between Python Dictionaries and JSON
We will use json.dums() function to convert to json from python dictionary and json.loads() to convert from json to python dictionary. In this example code we used flower details data in python dictionary and converted it to json. import json # flowers in python dictionary flowers = { “rose”: { “scientific_name”: “Rosa”, “grows_in”: [“gardens”, “wild”],…
-
Storing and retrieving data from sqlite with python
For making everything simpler we will use peewee orm with python sqlite3…. First create and connect to our database from peewee import * # SQLite database setup with Peewee db = SqliteDatabase(‘cv_database.db’) class User(Model): username = CharField(unique=True) # Add more user details as needed class Meta: database = db class CV(Model): user = ForeignKeyField(User, backref=’cv’)…
-
How to create or remove files or folders using python
The easiest way to create or remove file is using python os module To create file To create folder To remove file To remove folder The consideration. If file already exist when creating file it will show error so we can check if the file already exist or when deleting folder