Static methods in Python example

Static methods are almost similar to normal methods inside a class but the only difference is static methods can be called from out side the class without initializing the object of that class.This means a static method can be called without using an object, it can be called using CLASSNAME.STATIC_METHOD_NAME.

Lets see Static methods example

1) Static method example using @staticmethod

class Currency_convert:

    # create Dollar_Ringgit_convert static method
    @staticmethod
    def Dollar_Ringgit_convert(doll):
        return doll * 4.35

print('Dollar to Ringgit Convert :', Currency_convert.Dollar_Ringgit_convert(150))

2) Static method example using staticmethod()

class Currency_convert:

    # create Dollar_Ringgit_convert static method
    def Dollar_Ringgit_convert(doll):
        return doll * 4.35

Currency_convert.Dollar_Ringgit_convert = staticmethod(Currency_convert.Dollar_Ringgit_convert)

print('Dollar to Ringgit Convert :', Currency_convert.Dollar_Ringgit_convert(150))

static methods in python

machine learning project in python for beginners

Here is the simple machine learning project in python for beginners, it is actually some machine learning application to predict 2BHK apartment price in a specified city.So first we should explain what is machine learning, it is actually a technique that enable a system to learn from data.In simple it will learn from the data you have given and tell u next data based on the learning.
To do machine learning project in python you have to download anaconda you can download it from the website www.anaconda.com based on python version you can download any of the release.Then double click and install in your sytem.after installing open anaconda and create a new file and name it as myfirstML.py (any name you can give)

SO Lets start coding

1) First we are importing pandas module see code

import pandas

Of course you will ask me what is pandas ,in simple pandas is a library used for data manipulations and analysis.

2) Next assign given data in variable ,we have data of last 10 year price of 2BHK apartment

See below test.csv file

2010,180000
2011,220000
2012,240000
2013,250000
2014,260000
2015,290000
2016,320000
2017,360000
2018,400000
2019,500000
2020,550000

url='test.csv'
names=['year','price-for-2BHK']

3) Read CSV with the help of pandas library function

datas= pandas.read_csv(url,names=names)

4) Read CSV with the help of pandas library function

datas= pandas.read_csv(url,names=names)

5) Print data and make sure that we are fecthing data in a variable correctly

print(datas[['price-for-2BHK']])

6) Assign year and price-for-2BHK in respective varibale x and y


x=datas[['year']];
        
y=datas[['price-for-2BHK']]

7) Import train_test_split and split data using train_test_split

train_test_split is a function in sklearn model selection for spiliting data arrays in to two subsets , for training data and for testing data with this function no need to divide the data manually


from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test =train_test_split(x,y,test_size=0.1,random_state=101)

8) import LinearRegression from sklearn.linear_model

LinearRegression is statistical method used to create a linear model.This model describe the relationship between a dependent variable y as function of one or more independent variable


from sklearn.linear_model import LinearRegression

9) Use LinearRegression() and fit method

LinearRegression is statistical method used to create a linear model.This model describe the relationship between a dependent variable y as function of one or more independent variable


model= LinearRegression()
model.fit(X_train,Y_train)

10) Finally predict the price based on the year

print(model.predict([[2030]]))

Output

2BHK price in 2030 :855446.85990338

See full code

import pandas
url="test.csv"
names=['year','price-for-2BHK']

datas= pandas.read_csv(url,names=names)

print(datas[['price-for-2BHK']])

x=datas[['year']];
        
y=datas[['price-for-2BHK']]

from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test =train_test_split(x,y,test_size=0.1,random_state=101)

from sklearn.linear_model import LinearRegression

model= LinearRegression()
model.fit(X_train,Y_train)

print(model.predict([[2030]]))

How to convert a integer value to word in python

To convert a integer value to word in python our aim is to convert 124 to “One Hundred Twenty Four”

Here is python code to convert integer value to word

def Towords(num):
	under_20 = ['Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']
	tens = ['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']
	above_100 = {100: 'Hundred',1000:'Thousand', 1000000:'Million', 1000000000:'Billion'}
	if num < 20:
		 return under_20[num]

	if num < 100:
		return tens[(int)(num/10)-2] + ('' if num%10==0 else ' ' + under_20[num%10])
	# find the appropriate pivot - 'Million' in 3,603,550, or 'Thousand' in 603,550
	pivot = max([key for key in above_100.keys() if key <= num])
	return Towords((int)(num/pivot)) + ' ' + above_100[pivot] + ('' if num%pivot==0 else ' ' + Towords(num%pivot))


print(Towords(124))

Output

One Hundred Twenty Four

How to convert a integer value to word in python

tiger view in 3d not working in my phone

tiger view in 3d not working my phone

View in 3d is a new feature in smart devices it allow you to view the animal in 3D format.But it is visible only in google core compatible mobile phone.Here is the list of mobile phone that will work view in 3d options

Asus Zenfone AR
Asus Zenfone ARES
Google Nexus 5X
Google Nexus 6P
Google Pixel, Pixel XL
Google Pixel 2, Pixel 2 XL
Google Pixel 3, Pixel 3 XL
Nokia 6 (2018)
Nokia 6.1 Plus
Nokia 7 Plus
Nokia 8
Nokia 7.1
Nokia 8 Sirocco
Honor 8X
Honor View 10 Lite
Honor 10
Honor V20
Nova 3, Nova 3i
Huawei Mate 20 Lite
Huawei Mate 20 Pro
Huawei Mate 20 X
Nova 4
Huawei y9 (2019)
Huawei P20, P20 Pro
Huawei Mate RS Porsche Design
LG G6
LG G7 One
LG G7 ThinQ
LG V30, V30+, V30+ JOJO
LG V35 ThinQ
LG Q6
LG V40
LG Q8
Moto G5S Plus
Moto G6
Moto Z2 Force
Moto Z3
Moto Z3 Play
Moto Z2 Force
Moto X4
Moto One
Moto One Power
OnePlus 3T
OnePlus 5
OnePlus 6
OnePlus 6T
Samsung Galaxy A5 (2017)
Samsung Galaxy A7 (2017)
Samsung Galaxy A8, Samsung Galaxy A8+ (2018)
Samsung Galaxy Note 8
Samsung Galaxy S7, Galaxy S7 Edge
Samsung Galaxy S8, Galaxy S8+
Samsung Galaxy S9, Galaxy S9+
Galaxy Tab S3
Galaxy Tab S4
Xiaomi Mi Mix 2S
Xiaomi Mi 8
Xiaomi Mi 8 SE
Mi Mix 3
Pocofone F1
Vivo Nex S
Vivo Nex dual display
Sony Xperia XZ Premium
Xperia XZ1, Xperia XZ1 Compact
Xperia XZ2, Xperia XZ2 Compact, Xperia XZ2 Premium
Xperia XZ3


Here is the list of animals that can view in 3d

Lion
Tiger
Cheetah
Shark
Hedgehog
Duck
Emperor penguin
Wolf
Angler fish
Goat
Rottweiler
Snakes
Eagle
Brown bear
Alligator
Horse
Shetland pony
Macaw
Pug
Turtle
Cat
Octopus
Dog
Golden Retriever