Skip to content

Commit

Permalink
new changes added
Browse files Browse the repository at this point in the history
  • Loading branch information
linrakesh committed May 21, 2020
2 parents a463ce0 + da25a2a commit 99b44d3
Show file tree
Hide file tree
Showing 66 changed files with 588 additions and 42 deletions.
18 changes: 9 additions & 9 deletions DataStructure/queue.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#function to add element at the end of list
def add_element(stack,x):
stack.append(x)
def add_element(queue,x):
queue.append(x)
#function to remove last element from list
def delete_element(stack):
n = len(stack)
def delete_element(queue):
n = len(queue)
if(n<=0):
print("Queue empty....Deletion not possible")
else:
del(stack[0])
del(queue[0])

#function to display stack entry
def display(stack):
if len(stack)<=0:
#function to display queue entry
def display(queue):
if len(queue)<=0:
print("Queue empty...........Nothing to display")
for i in stack:
for i in queue:
print(i,end=" ")
#main program starts from here
x=[]
Expand Down
23 changes: 23 additions & 0 deletions ModuleExamples/createModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def hello():
for x in range(10):
print('hello', x, end =" ")

def sum_digit(n):
sum1 = 0
while n!=0:
sum1 += n%10
n = n//10
return sum1

def simple_interest(p,r,t):
return p*r*t/100

def area_triangle(base,height):
return base*height

def isPrime(n):
found =0
for x in range(2,(n//2)+1):
if n%x==0:
found=1
return found
8 changes: 8 additions & 0 deletions ModuleExamples/module_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from createModule import isPrime


result = isPrime(11)
if result ==0:
print('Prime Number')
else:
print('Not a prime Number')
3 changes: 2 additions & 1 deletion assignment_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import random

unique=[]
Expand Down Expand Up @@ -40,4 +41,4 @@
if(counter>=6):
break

print(string)
print(string)
29 changes: 29 additions & 0 deletions delete_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import csv
name = input('Name to delete :')
# this is comment
# hello rakesh this is comment
""" this is multi line commnet"""

records=[]
found =0
file = open("student.csv","r")
reader = csv.DictReader(file)
for record in reader:
record = dict(record)
if(record['name']!=name):
records.append(dict(record))
else:
found =1
file.close()
# Remove the old file and create a new csv file
headers=['rollno','name','stream','fees']
file = open("student.csv","w")
writer = csv.DictWriter(file,fieldnames =headers, lineterminator ='\n')
writer.writeheader()
writer.writerows(records)
file.close()

if(found==0):
print(name, " does not exists")
else:
print(name," deleted successfully")
6 changes: 3 additions & 3 deletions fileHandling/Create_binary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Compiled on : 27-Nov-2019

import pickle
list = []
list1 = []
while True:
roll = input("Enter student Roll No:")
sname = input("Enter student Name :")
student = {"roll": roll, "name": sname}
list.append(student)
list1.append(student)
choice = input("Want to add more record(y/n) :")
if(choice == 'n'):
break

file = open("student.dat", "wb")
pickle.dump(list, file)
pickle.dump(list1, file)
file.close()
3 changes: 1 addition & 2 deletions fileHandling/Update_binary_file_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import pickle

name = input('Enter name that you want to update in binary file :')

name = input('Name to update :')
file = open("student.dat", "rb+")
list = pickle.load(file)

Expand Down
13 changes: 13 additions & 0 deletions fileHandling/binary_files/create_bn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pickle
rec=[]
while True:
roll= int(input('Enter Name :'))
name=input('Enter your Name : ')
record = [roll, name]
rec.append(record)
choice=input('Add More(Y/N ) ? ')
if choice.upper() == 'N':
        break
f = open("student", "wb")
pickle.dump(rec, f)
f.close()
15 changes: 15 additions & 0 deletions fileHandling/csv Files/AddRecord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv

rollno= int(input('Roll No :'))
name = input('Name :')
stream = input('Stream :')
fees = int(input('Fees :'))

records = [rollno,name,stream,fees]

f = open("student.csv", "a")
csvwriter = csv.writer(f, lineterminator='\n')
# csvwriter.writerow(header)
csvwriter.writerow(records)
f.close()
print("Record added ...")
24 changes: 24 additions & 0 deletions fileHandling/csv Files/deleteRecord_readerWriter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# program to update a record in csv file
import csv
name = input('Name to Delete :')
records = []
found = 0
file = open("student.csv", "r")
reader = csv.reader(file)
for record in reader:
if(record[1]!= name):
records.append(record)
found = 1

file.close()

# Remove the old file and create a new csv file
file = open("student.csv", "w")
writer = csv.writer(file,lineterminator='\n')
writer.writerows(records)
file.close()

if(found == 0):
print(name, " does not exists")
else:
print(name, " deleted successfully")
Empty file.
6 changes: 6 additions & 0 deletions fileHandling/csv Files/readcsvFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import csv
f = open(r"C:\Users\rakesh\Desktop\student.csv", "r")
data = csv.reader(f)
for record in data:
print(record)
f.close()
6 changes: 6 additions & 0 deletions fileHandling/csv Files/readcsvUsingDictReader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import csv
f = open(r"C:\Users\rakesh\Desktop\student.csv", "r")
data = csv.DictReader(f)
for record in data:
print(dict(record))
f.close()
15 changes: 15 additions & 0 deletions fileHandling/csv Files/search_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv
name = input('Name to Search :')

file = open('student.csv','r')
reader = csv.DictReader(file)
found =0
for x in reader:
x = dict(x)
if(x['name']==name):
print(name,' found in CSV file..')
found =1
file.close()

if(found == 0):
print(name, ' not found....')
14 changes: 14 additions & 0 deletions fileHandling/csv Files/search_record_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import csv
name = input('Name to Search :')

file = open('student.csv', 'r')
reader =csv.reader(file)
found = 0
for x in reader:
if(x[1] == name):
print(name, ' found in CSV file..')
found = 1
file.close()

if(found == 0):
print(name, ' not found....')
1 change: 1 addition & 0 deletions fileHandling/csv Files/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 31 additions & 0 deletions fileHandling/csv Files/updateCSV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# program to update a record in csv file
import csv
name = input('Name to Update :')
records = []
found = 0
file = open("student.csv", "r")
reader = csv.DictReader(file)
for record in reader:
record = dict(record)
if(record['name'] == name):
record = dict(record)
record['name'] =input('New Name:')
records.append(record)
found=1
else:
records.append(dict(record))
file.close()

# Remove the old file and create a new csv file
pr
headers = ['rollno', 'name', 'stream', 'fees']
file = open("student.csv", "w")
writer = csv.DictWriter(file, fieldnames=headers, lineterminator='\n')
writer.writeheader()
writer.writerows(records)
file.close()

if(found == 0):
print(name, " does not exists")
else:
print(name, " updated successfully")
15 changes: 15 additions & 0 deletions fileHandling/csv Files/writeCSVFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv
records =[
["ID", "name", "Price", "Qty"],
["102","LG Monitor","6500","20"],
["103","KeyBoard","1350","156"],
["105","Hp Mouse","650","120"],
["106","Speaker","1670","136"]
]

f = open("stock.csv","w")
csvwriter = csv.writer(f,lineterminator="\n")
# csvwriter.writerow(header)
csvwriter.writerows(records)
f.close()
print("Check your file now....")
15 changes: 15 additions & 0 deletions fileHandling/csv Files/writeCsvDictWriter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv
headers =['rollno','name','stream','fees']
records = [
{'fees': 2356,'rollno': 12, 'name': 'surendra', 'stream': 'Humanities', },
{'rollno': 13, 'stream': 'Humanities', 'fees': 2356,'name': 'Ashok', },
{'rollno':15,'name':'Nipun','stream':'Humanities','fees':2356},
{'rollno': 22, 'name': 'Ayush Negi', 'fees': 2356,'stream': 'Science', },
]

f = open("student.csv", "w")
writer = csv.DictWriter(f, fieldnames = headers, lineterminator='\n')
writer.writeheader()
writer.writerows(records)
f.close()
print("Check your file now....")
2 changes: 2 additions & 0 deletions fileHandling/csvReader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


import csv
import xlwt
from tabulate import tabulate
Expand Down
3 changes: 2 additions & 1 deletion fileHandling/read_binary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

file = open("student.dat", "rb")
list = pickle.load(file)
print(list)
for x in list:
print(x['roll'],x['name'])
file.close()
8 changes: 3 additions & 5 deletions fileHandling/search_in_binary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
# Compiled on : 8-July-2018

import pickle

name = input('Enter name that you want to search in binary file :')

name = input('Name to search :')
file = open("student.dat", "rb")
list = pickle.load(file)
list1 = pickle.load(file)
file.close()

found = 0
for x in list:
for x in list1:
if name in x['name']:
found = 1
print("Found in binary file" if found == 1 else "Not found")
7 changes: 4 additions & 3 deletions matplotlib/bar_Graph.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# program to print bar graph on the screen
# made by : rakesh kumar

import numpy as np
import matplotlib.pyplot as plt
x = ['Delhi', 'Banglore', 'Chennai', 'Pune']
y = [250, 300, 260, 400]
city = ['Delhi', 'Banglore', 'Chennai', 'Pune']
sales = [250, 300, 260, 400]
plt.xlabel('City')
plt.ylabel('Sales in Million')
plt.title('Sales Recorded in Major Cities')
plt.bar(x, y)
plt.bar(city, sales)
plt.show()
5 changes: 5 additions & 0 deletions matplotlib/box_plot1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import matplotlib.pyplot as plt
x = [1, 3, 4, 7, 8, 8, 9]
plt.boxplot(x)
plt.grid()
plt.show()
7 changes: 7 additions & 0 deletions matplotlib/box_plot2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import matplotlib.pyplot as plt
list1 = [10, 33, 43, 74, 84, 8, 9,35,63,5,3,67,8,78,35,2,57,7,78,34,67,34]
list2 = [23,3,5,67,67,78,98,90,100,12,45,67,89,45,56,78,9,23,69,56,23,5]
plt.boxplot([list1,list2],labels=['Girls','Boys'])
plt.grid()
plt.legend()
plt.show()
8 changes: 8 additions & 0 deletions matplotlib/boxplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import matplotlib.pyplot as plt
import numpy as np
import numpy as np
x = np.arange(1,100)
y = np.arange(101,200)
z= np.arange(201,250)
plt.boxplot([x,y,z])
plt.show()
21 changes: 21 additions & 0 deletions matplotlib/frequency_polygon.py
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
import matplotlib.pyplot as plt
<<<<<<< HEAD
=======
from numpy import linspace,pi,sin,cos,tan

#multiple figures
data=[1,2,3,4,5,
10,11,12,14,15,18,16,14,13,12,19,20,16,14,19,
22, 21, 22, 23, 24, 25, 23, 26, 28, 26,27,25,28,29,30,
32,33,37,38,38,39,34,36,
42,43,45,46,48,46,49,50,43,42,44,45,47,49,50,49,48,42,46,41,45,46,48,45,44,
51,52,54,55,53,58,57,59,60,52,51,54,53
]
frequency = [5,15,18,8,25,13]
x = [5,15,25.5,35.5,45.5,55.5]


plt.figure(1)
plt.hist(data,bins=[0,10,20,30,40,50,60],color="green")
plt.scatter(frequency,x)
plt.show()
>>>>>>> da25a2a32ac30d0980ed6d1d3ad58008d8ff0b21
Loading

0 comments on commit 99b44d3

Please sign in to comment.