View ShoppingList.py
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: |
View Incrementor.py
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 |
View FoodCalculator.py
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) |
View library.py
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]) |
View TwoStacksQueue.py
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): |
View DataCenter.java
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(); |
View BSTimplementation.java
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 |
View SortByFrequency.py
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 |
View indexquestion.py
'''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] |
View indexquestion.py
'''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] |
NewerOlder