Skip to content

Instantly share code, notes, and snippets.

View shreezan123's full-sized avatar

Shrijan Aryal shreezan123

View GitHub Profile
class ShoppingList:
cart = {}
def __init__(self):
pass
def add_item(self,name,price):
self.cart[name] = price
def remove_item(self,name):
if name in self.cart:
class Incrementor:
array = []
value = 0
arrayVals = []
def __init__(self,array):
self.array = array
def add_value(self,value):
self.value = value
def add_values(self,valuesArr):
self.arrayVals = valuesArr
class FoodCalculator:
current_price = 0
def __init__(self):
pass
def add_item(self,value):
self.current_price = value #assign to instance variable
def get_tax(self,tax_rate):
return self.current_price*(tax_rate*0.01)
def get_tip(self,taxP,tipP):
after_tax = self.current_price+(0.01*taxP*self.current_price)
class Library:
d1 = {}
def __init__(self):
pass
def add_book(self,book):
self.d1[book] = True
def check_out_book(self,book):
if book in self.d1:
del(self.d1[book])
@shreezan123
shreezan123 / TwoStacksQueue.py
Created March 6, 2018 00:22
Implement a queue using two stacks
class QueueUsingStacks:
def __init__(self):
self.stack1 = []
self.stack2 = []
def enqueue(self,value):
self.stack1.append(value)
#if empty, pop from stack1 and put each value in stack2.
def dequeue(self):
@shreezan123
shreezan123 / DataCenter.java
Created June 18, 2017 08:50
Take input from txt file and perform respective job in the tree
package lab5;
import java.util.Scanner;
public class DataCenterOrders {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int numOperations = in.nextInt();
// create object of BinarySearchTree class
BinarySearchTree tree1 = new BinarySearchTree();
@shreezan123
shreezan123 / BSTimplementation.java
Created June 18, 2017 08:42
BST implementation. To keep all the classes under a same class file, I have commented out the main function
package lab5;
import java.util.ArrayList;
public class BinarySearchTree {
public class Node {
public int data;
public Node left;
public Node right;
/*
* Constructor if in which a value is passed, a Node
@shreezan123
shreezan123 / SortByFrequency.py
Created February 27, 2017 07:13
Sorting items in the list by the number of occurences
def SortByFrequency(list1):
d1 = {}
list2 = []
for items in list1:
d1[items] = list1.count(items)
for thekeys in d1:
for i in range(0,d1[thekeys]):
list2.append(thekeys)
return list2
@shreezan123
shreezan123 / indexquestion.py
Created February 26, 2017 21:17
A confusion related to index of for loop.
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?'''
str1 = "abcde"
str2 = ""
for i in range(len(str1)):
if str1[i] == "a":
i +=1
continue
else:
str2 += str1[i]
@shreezan123
shreezan123 / indexquestion.py
Created February 26, 2017 21:17
A confusion related to index of for loop.
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?'''
str1 = "abcde"
str2 = ""
for i in range(len(str1)):
if str1[i] == "a":
i +=1
continue
else:
str2 += str1[i]