Skip to content

Commit 2f8e6ad

Browse files
harshit.kackerharshit.kacker
authored andcommitted
First commit
0 parents  commit 2f8e6ad

19 files changed

+419
-0
lines changed

API.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import time as t
2+
import datetime
3+
from _datetime import date
4+
5+
print("sleeping")
6+
print(t.sleep(5))
7+
8+
print(datetime.date.today())
9+
print(datetime.datetime.now())

Demo.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
""" This is my first python code
2+
3+
age= int(input("Enter the age"))
4+
if age > 18 and age < 60:
5+
print("can vote")
6+
elif age < 18 and age > 1:
7+
print("not allowed")
8+
else :
9+
print("invalid age") """
10+
###################################
11+
info = r"My name is \n 'harshit'"
12+
print(info)
13+
####################################
14+
print("'harshit'" in info)
15+
print(info.count("i"))
16+
print(info.index("'harshit'"))
17+
for char in info:
18+
print(char , end = " ")
19+
print(info[0:10])
20+
print(info.split(sep=" "))
21+
########################################
22+
mylist =list([10,20,30,10,40,50,"harshit"])
23+
print(type(mylist))
24+
print(mylist[0:4])
25+
########################################
26+
mylist.append("newly added")
27+
mylist.insert(0, "first")
28+
print(mylist)
29+
print(30 in mylist)
30+
print(mylist.count(10))
31+
#########################################
32+
print(len(mylist))
33+
print(mylist.reverse())
34+
print(mylist)
35+
print(mylist.pop(0))
36+
#########################################
37+
mytupple = (10,20,30,"harshit")
38+
print(type(mytupple))
39+
#print(mytupple.append("newly added"))
40+
print(3 in mytupple)
41+
for val in mytupple :
42+
print(val)
43+
print(mytupple[0:3])
44+
##########################################
45+
mylist1=[10,90,20]
46+
mytupple2=tuple(mylist1)
47+
print(type(mytupple2))
48+
##########################################
49+
mytupple3 =("harshit")
50+
mytupple4 =tuple("66")
51+
print(type(mytupple3))
52+
print(type(mytupple4))
53+
#########################################
54+
myset={10,3,4,6,20}
55+
myset2={30,7,90,8}
56+
print(type(myset))
57+
print(3 in myset)
58+
print(myset.add(69))
59+
print(myset)
60+
for val in myset:
61+
print(val)
62+
##########################################
63+
print(myset.union(myset2))
64+
print(myset.difference(myset2))
65+
print(myset.issuperset(myset2))
66+
##########################################
67+

decorator.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def mydec(anyfunc):
2+
def inner(*val):
3+
print("This is pre task")
4+
anyfunc(*val)
5+
print("The argument values",val, "func name is",anyfunc.__name__)
6+
print("This is post task")
7+
return inner
8+
9+
@mydec # This is linking to decorator so , first decorator will execute
10+
def add(num1 , num2):
11+
print("This is add function", num1+num2)
12+
13+
@mydec
14+
def login(username , password):
15+
print("login function")
16+
17+
add(10 , 20)
18+
login("harshit", 1234)

demo.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ID Name Age
2+
1.01 Sam 0.35
3+
1.02 Harry 0.27
4+
1.03 Ravi 0.37

demo_cmd.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
fp = open("C:/Users\harshit.kacker\eclipse-workspace\python_first\sample.txt")
3+
print(fp.read())
4+
fp.seek(0) # goes back to first character of the line
5+
mylist =fp.readlines()
6+
7+
for val in mylist :
8+
print(val)
9+
fw = open("sample_output.txt",'w')
10+
fw.write("Learning python is very interesting")
11+
fw.write("\npython can be used in Analytics also")
12+
fw.write("\nspark code can also written in python")
13+
fw.close()
14+
print("data Written")
15+
"""
16+
17+
"""fw = open("sample_output.txt",'a+')
18+
fw.write("\nlast Line")
19+
fw.seek(0)
20+
print(fw.readlines())
21+
print(fw) """
22+
23+
fp1 = open("demo.csv","r")
24+
print(fp1.read())
25+
26+
fp = open("nwedemo.csv",'w')
27+
fp.write("\nPid,name")
28+
fp.write("\n101,Food")
29+
fp.write("\n102,Coffee")
30+
fp.close()
31+
print("data written")

first_class.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Person :
2+
def show(self):
3+
print("show in person")
4+
5+
class Human :
6+
def show(self):
7+
print("show in Human")
8+
9+
class Employee(Person,Human):
10+
11+
"""This is Employee class (will
12+
only display if put at first)"""
13+
14+
cname ="Accenture"
15+
16+
def __init__(self,eid ,name):
17+
print("inside init")
18+
self.__empid = eid
19+
self.__empname = name
20+
print(self.__empid," ",self.__empname)
21+
22+
23+
def info(self):
24+
super().show() #to access parent class
25+
print(self.__empid)
26+
27+
def show(self): # this is overriding but overloading is not supported
28+
print(self.__empid)
29+
30+
print(Employee.__doc__)
31+
print(Employee.cname)
32+
obj=Employee(101,"sam")
33+
#print(obj.__empid," ",obj.__empname)
34+
#__ is used to make function private
35+
print(obj.info())
36+
obj.show()

map_plot.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import matplotlib.pyplot as mt
2+
import pandas as pd
3+
4+
df =pd.read_csv("nwedemo.csv")
5+
#df["Age"].plot(kind="bar")
6+
#df.plot(kind="bar")
7+
df["Age"].plot(kind="pie")
8+
mt.ylabel("Age")
9+
mt.xlabel("Row numbers")
10+
mt.show()
11+
12+
13+
"""size = [40,30,30]
14+
lab=["india","USA","UK"]
15+
exp =[0,0,0.5]
16+
17+
mt.pie(x=size , labels=lab, colors=["red","Orange","Brown"], explode=exp)
18+
mt.title("Country")
19+
mt.show()"""
20+
21+
""""y=[90,80,60,93,68,40,50]
22+
x=["Harry","sam","Rohan","Neha","Shruti","Surabhi","Kanu"]
23+
mt.bar(x,y,width=0.3 , color=["red","Green"])
24+
mt.ylabel("percentages")
25+
mt.xlabel("Names")
26+
mt.show()"""
27+

new_data.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ID,Name,Age
2+
101,Harshit,27
3+
102,neha,26
4+
103,surabhi,26
5+
104,kanu,25

newdemo.csv

Whitespace-only changes.

numpy_python.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import numpy as np
2+
print(np.__version__)
3+
4+
mylist = [10,20,40,50]
5+
print(mylist*2)
6+
7+
myarr = np.array(mylist)
8+
print(type(myarr))
9+
print(myarr*2)
10+
11+
print(np.append(myarr,100))
12+
print(np.insert(myarr,0,1))
13+
14+
myarr2= np.array((10,20,40,50))
15+
print(myarr2)
16+
17+
print(mylist+mylist)
18+
print(myarr+myarr2)
19+
20+
newarr = np.array([10,20,30,50,40])
21+
print(newarr)
22+
23+
my2darr = np.array([[1,2,39],[58,5,27],[6,57,8]])
24+
print(my2darr)
25+
print(np.max(my2darr))
26+
print(np.min(my2darr))
27+
print(np.sum(my2darr))
28+
print(np.sum(my2darr,axis=0))
29+
print(np.sum(my2darr,axis=1)) # axis=0 means rows wise axis=1 means column wise
30+
print(my2darr.T)
31+
32+
for val in my2darr :
33+
for data in val :
34+
print(data,end=" ")

0 commit comments

Comments
 (0)