#include<stdio.h>
int chkpal(char [],int);
void main()
{
char name[] = “892198”;

int length = 0;

int j;
printf(“%s\n”, name);

 

while (name[length]!= ‘\0’)
{

length++;

 

}

printf(“the length is %d\n”, length);

j=chkpal(name, length);
if (j == 1)
printf(“pal\n”);
else
printf(“not pal\n”);

}

 

int chkpal(char name[],int length)
{
printf(“the name is %s\n”, name);
static int num=0;
printf(“character name[%d]=%c name[%d]=%c is being compared\n”, length-1, name[length-1], num, name[num]);
if (name[length – 1] == name[num])
{
length = length – 1;
num = num + 1;
if (num <length-1)
chkpal(name, length);
else
return 1;

}
else
{
return 0;

}

}

Advertisements

import subprocess
def uname_func():
uname=’uname’
uname_arg=’-a’
print ‘Gathering system information with %s command:\n’ %uname
subprocess.call([uname,uname_arg])
def disk_func():
diskspace=’df’
diskspace_arg=’-h’
print ‘Gathering diskspace information with %s command:\n’ %diskspace
subprocess.call([diskspace,diskspace_arg])
def main():
uname_func()
disk_func()
if __name__==’__main__’:
main()

 

Source:Oreilly book python for unix and linux System Administration,a truly wonderful book

#include<stdio.h>

 

void main()
{
char name[]=”abba”;
char c=’z’;
int length=0;
char reversename[100];
int j=0;
char signal=’T’;
printf(“%s\n”,name);

 

while (c!=’\0′)
{
c=name[length];
length++;

 

}

printf(“the length is %d\n”,length-1);

 

for(int i=(length-2);i>=0;i=i-1)

{

printf(“name[%d] is %c\n”,i,name[i]);
reversename[j]= name[i];
j++;

}
printf(“reversename is %s\n”,reversename);
j=0;
for(j=0;j<=((length)-2);j=j+1)

{
printf(“character reversename[%d]=%c name[%d]=%c is being compared\n”,j,reversename[j],j,name[j]);
if (reversename[j]!=name[j])
{
//printf(“not matched”);
signal=’F’;
}

 

}
if (signal==’T’)
printf(“palindrome\n”);
else
printf(“not pal\n”);

}

import os
import shutil
from shutil import copyfile

choice=’2′
##mylist=[]
##for elem in os.listdir(‘/home/sourav/Desktop/folder1’):
## if ‘jpg’ in elem:
## mylist.append(elem[:len(elem)-4])
## elif ‘png’ in elem:
## mylist.append(elem[:len(elem)-4])
## else:
## pass
##
##
##print mylist
for elem in os.listdir(‘/home/sourav/Desktop/folder1’):
if ‘jpg’ in elem or ‘png’ in elem:
## print choice, elem[:len(elem)-4]
if choice==elem[:len(elem)-4]:

copyfile(‘/home/sourav/Desktop/folder1/’ + elem, ‘/home/sourav/Desktop/folder2/.’+elem)

else:
pass

##mylist2=[]
##
##for pic in mylist:
##
## #print pic[len(pic)-4:len(pic)]
##
## mylist2.append(pic[:len(pic)-4])
##print mylist2

import numpy as np
create a rank 1 array

l=[[1,2],[4,5],[3,6]]
l=[[1,2],[3,6],[4,5]]
l=[[1,2],[4,5],[3,6]]

##print type(l)
k=[3,6,1,80,0,4]

if type(l) is list:
print ‘l is a list’

sortelem=[]
for elem in l:
if type(elem) is list and len(elem)>0:
sortelem.append(elem[0])

##print sortelem
sortelem.sort()

print sortelem
index
for i in range(0,len(sortelem)):
for j in range(0,len(l):
if sortelem[i]=l
##
l.sort(key=lambda l:l[1])
print l

 

x=np.array([2,4,3,1])
print x

print type(x)

print x.shape

x[0]=102

print x

 

y=np.array([[4,5,6],[5,2,7]])
print y

print type(y)

print y.shape

 

w=np.zeros((3,3))
print w

print w.shape

w=np.ones((3,3))
print w

w=np.full((4,4),10,dtype=np.int64)

print w

r=(np.random.random((5,5)))

print r

 

i=np.eye(4,4)

print i

list1=[4,6,7,2,10]
f=np.array(list1)
print type(f)

 

g=np.arange(20)

print g

print g.shape

 

h=np.array([[0,1,2,0],[0,1,2],(4+5j,10,25)])

print h[0]

floatarray=np.arange(1,20,dtype=np.float64)

print floatarray

 

j=np.linspace(0,100,10,dtype=np.longdouble)

print j

 

l=[[1,2],[4,5],[3,6]]

l.sort(key=lambda l:l[1])
print l

import pandas as pd
import quandl
import math

data=quandl.get(‘WIKI/GOOGL’)
data=data[[‘Adj. Open’,’Adj. High’,’Adj. Low’,’Adj. Close’,’Adj. Volume’]]
data[‘HL_PCT’]=(data[‘Adj. High’]-data[‘Adj. Close’])/data[‘Adj. Close’]*100.0
data[‘PCT_CHANGE’]=(data[‘Adj. Close’]-data[‘Adj. Open’])/data[‘Adj. Open’]*100.0
data=data[[‘Adj. Close’,’HL_PCT’,’PCT_CHANGE’,’Adj. Volume’]]

 

#print len(data)
forecast_col=’Adj. Close’
data.fillna(-99999,inplace=True)
forecast_out=int(math.ceil(0.0001*len(data)))
data[‘label’]=data[forecast_col].shift(-forecast_out)
print data.head(10)

mydict={‘name’:’sourav’,’roll’:25}

for i in mydict.itervalues():
print mydict.keys()[mydict.values().index(i)]]

Posted by: Sourav | June 22, 2017

None output from python solved

https://stackoverflow.com/questions/7053652/random-none-output-from-basic-python-function

from nsepy import get_history, get_index_pe_history
from datetime import date

sbin = get_history(symbol=’SBIN’,
start=date(2015,1,1),
end=date(2015,1,10))
sbin[[ ‘VWAP’, ‘Turnover’]].plot(secondary_y=’Turnover’)

nifty = get_history(symbol=”NIFTY”,
start=date(2015,1,1),
end=date(2015,1,10),
index=True)
nifty[[‘Close’, ‘Turnover’]].plot(secondary_y=’Turnover’)

 

#Futures and Options historical data
nifty_fut = get_history(symbol=”NIFTY”,
start=date(2015,1,1),
end=date(2015,1,10),
index=True,
futures=True, expiry_date=date(2015,1,29))

stock_opt = get_history(symbol=”SBIN”,
start=date(2015,1,1),
end=date(2015,1,10),
option_type=”CE”,
strike_price=300,
expiry_date=date(2015,1,29))

#Index P/E ratio history
nifty_pe = get_index_pe_history(symbol=”NIFTY”,
start=date(2015,1,1),
end=date(2015,1,10))

 

print nifty_fut

Older Posts »

Categories

%d bloggers like this: