This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter: | |
count = 0 # class attribute count | |
def increment(): # define method to increment count | |
count += 1 | |
Counter.count # count is 0 | |
Counter.increment() # call the method increment() | |
Counter.count # count is 1 | |
counter = Counter() # create instance of Counter | |
counter.count # class attribute... count is still 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter: | |
def __init__(self): # define __init__ method passing self | |
self.count = 0 # set instance attribute count to 0 | |
def increment(self): # define increment method passing self | |
self.count += 1 # add 1 to instance attribute count | |
c1 = Counter() # create Counter instance | |
c2 = Counter() # create another instance | |
c1.increment() # increment counter for c1 | |
c1.count # count is 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
data = pd.read_csv('fruit_data.csv') | |
types = pd.read_csv('fruit_types.csv', index_col=0) | |
y = data['Label'] | |
X = data[['Mass', 'Width', 'Height']] | |
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Label | Mass | Width | Height | |
---|---|---|---|---|
1 | 192 | 8.4 | 7.3 | |
1 | 180 | 8 | 6.8 | |
1 | 176 | 7.4 | 7.2 | |
2 | 86 | 6.2 | 4.7 | |
2 | 84 | 6 | 4.6 | |
2 | 80 | 5.8 | 4.3 | |
2 | 80 | 5.9 | 4.3 | |
2 | 76 | 5.8 | 4 | |
3 | 178 | 7.1 | 7.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sound | Average Frequency | Average Loudness | Duration | Distance | |
---|---|---|---|---|---|
A | -0.53 | -1.65 | -0.65 | 0 | |
C | 0.05 | -0.15 | -0.96 | 1.64 | |
B | -0.62 | 0.60 | 0.17 | 2.40 | |
E | 1.91 | -0.15 | -0.41 | 2.87 | |
D | -0.81 | 1.35 | 1.85 | 3.91 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Average Frequency | Average Loudness | Duration | |
---|---|---|---|
-0.53 | -1.65 | -0.65 | |
-0.62 | 0.60 | 0.17 | |
0.05 | -0.15 | -0.96 | |
-0.81 | 1.35 | 1.85 | |
1.91 | -0.15 | -0.41 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Average Frequency | Average Loudness | Duration | |
---|---|---|---|
440 | -6 | 3.4 | |
352 | -3 | 9.2 | |
1053 | -4 | 1.2 | |
153 | -2 | 20.9 | |
3002 | -4 | 5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import pow, truediv, mul, add, sub | |
operators = { | |
'+': add, | |
'-': sub, | |
'*': mul, | |
'/': truediv | |
} | |
def calculate(s): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num1 = input("First Number:\n") | |
operator = input("Operator (+, -, *, /):\n") | |
num2 = input("Second Number:\n") | |
num1 = float(num1) | |
num2 = float(num2) | |
out = None | |
if operator == "+": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String render() throws Exception | |
{ | |
HtmlTag hr = new HtmlTag("hr"); | |
if (extraDashes > 0) | |
hr.addAttribute("size", hrSize(extraDahses)); | |
return hr.html(); | |
} | |
private String hrSize(int height) | |
{ |