Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
906fbcf
initialized project and exercise 01
plucodev Sep 18, 2019
f3e1eda
initialized exercise 02
plucodev Sep 18, 2019
aa0b223
initialized exercise 03
plucodev Sep 18, 2019
cba4e25
initialized exercise 04
plucodev Sep 18, 2019
4ca3ef5
initialized exercise 05
plucodev Sep 18, 2019
666c6ce
initialized exercise 06
plucodev Sep 18, 2019
cccf689
initialized exercise 07
plucodev Sep 18, 2019
4806ba1
initialized exercise 08
plucodev Sep 18, 2019
dde938a
initialized exercise 09
plucodev Sep 18, 2019
76b27dc
initialized exercise 10
plucodev Sep 18, 2019
d772cfe
initialized exercise 11
plucodev Sep 18, 2019
7d3f565
initialized exercise 12
plucodev Sep 18, 2019
8764cbb
initialized exercise 13
plucodev Sep 18, 2019
271cca9
initialized exercise 14
plucodev Sep 18, 2019
8856354
initialized exercise 15
plucodev Sep 18, 2019
1eb01f5
initialized exercise 16
plucodev Sep 18, 2019
7244acd
initialized exercise 17
plucodev Sep 18, 2019
70bada7
initialized exercise 18
plucodev Sep 18, 2019
1502e98
initialized exercise 19
plucodev Sep 18, 2019
cd664d4
initialized exercise 20
plucodev Sep 18, 2019
e843f35
initialized exercise 21
plucodev Sep 18, 2019
ab4ddd5
initialized exercise 22
plucodev Sep 18, 2019
a059306
initialized exercise 23
plucodev Sep 18, 2019
63dc9ae
initialized exercise 24
plucodev Sep 18, 2019
3c319f3
initialized exercise 25
plucodev Sep 18, 2019
04db4e3
updated README 01 for Python
plucodev Sep 18, 2019
7830642
updated README 02 for Python
plucodev Sep 18, 2019
96c1a7f
fixed issues
plucodev Sep 18, 2019
199048f
completed 01
plucodev Sep 18, 2019
2331eb7
completed 01
plucodev Sep 18, 2019
b7b45a8
completed 02
plucodev Sep 18, 2019
863093f
completed 03-04-07 and fixed issues
plucodev Sep 18, 2019
494baf0
fixed issues 07
plucodev Sep 18, 2019
67d5020
completed 08
plucodev Sep 19, 2019
6780d10
fixed issues 08
plucodev Sep 19, 2019
f663440
updated 00
plucodev Sep 20, 2019
9935509
updated 05
plucodev Sep 24, 2019
6521ffa
updated 09
plucodev Sep 24, 2019
40c3e55
updated 10
plucodev Sep 24, 2019
6eec555
updated 11
plucodev Sep 24, 2019
c5b19f3
updated 12
plucodev Sep 24, 2019
14e0788
updated 13
plucodev Sep 25, 2019
ecaaa72
updated 13 and 14
plucodev Sep 25, 2019
6f79798
updated 17
plucodev Sep 25, 2019
ddbbdc8
updated 15
plucodev Sep 26, 2019
544913e
updated 16
plucodev Sep 26, 2019
17448f5
updated 13
plucodev Sep 26, 2019
5d7c381
updated 14
plucodev Sep 26, 2019
c88878a
updated 18
plucodev Sep 26, 2019
790bff9
updated 20
plucodev Sep 26, 2019
7a74ef8
updated 21
plucodev Sep 26, 2019
640bd6f
updated 12
plucodev Sep 26, 2019
4698f63
updated 21
plucodev Sep 26, 2019
5fe14a6
updated 22
plucodev Sep 26, 2019
c7fe498
updated 23
plucodev Sep 26, 2019
0feaf3f
updated 24
plucodev Sep 27, 2019
e4d881c
updated 25
plucodev Sep 27, 2019
69336d0
updated 25
plucodev Sep 27, 2019
79757da
updated 24
plucodev Sep 27, 2019
59eba4b
updated 23
plucodev Sep 27, 2019
8d2d02b
updated 21
plucodev Sep 27, 2019
ee9965f
updated 20
plucodev Sep 27, 2019
3f42207
updated 22
plucodev Sep 30, 2019
6946622
fixed issues 01-02-03-13
plucodev Oct 2, 2019
62db4c9
fixed issues 04
plucodev Oct 2, 2019
8cafcd7
fixed issues 05
plucodev Oct 2, 2019
7da8203
fixed issues 07
plucodev Oct 2, 2019
71d4172
fixed issues 08
plucodev Oct 2, 2019
a9520e7
fixed issues 09
plucodev Oct 2, 2019
5255d84
fixed issues 10
plucodev Oct 2, 2019
211f128
fixed issues 11
plucodev Oct 2, 2019
2e0bc06
fixed issues 12
plucodev Oct 2, 2019
e0d5a2a
fixed issues 12
plucodev Oct 2, 2019
1742933
fixed issues 13
plucodev Oct 2, 2019
ee37430
fixed issues 14-15-16
plucodev Oct 2, 2019
38d4e0e
fixed issues 17-18-19
plucodev Oct 4, 2019
0fb467b
fixed issues 21
plucodev Oct 4, 2019
f51d6be
fixed issues 22
plucodev Oct 4, 2019
f980101
fixed issues 23
plucodev Oct 4, 2019
e29047e
fixed issues 24 - 25
plucodev Oct 5, 2019
537d4e7
fixed issues 01 - 02
plucodev Oct 5, 2019
9dc7c9b
fixed issues 03
plucodev Oct 7, 2019
c9b5dc2
fixed issues 04
plucodev Oct 7, 2019
1fa2128
fixed issues 05
plucodev Oct 7, 2019
187af9f
deleted constant exercise
plucodev Oct 7, 2019
8500ea0
fixed genaral issues
plucodev Oct 7, 2019
98144e7
fixed issues 07-08-09-17-18
plucodev Oct 7, 2019
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated 25
  • Loading branch information
plucodev committed Sep 27, 2019
commit e4d881cd051391f07b95ca7fc81ab44253cd25af
59 changes: 24 additions & 35 deletions exercises/25-Python-Objects/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
# `25` Javascript Objects
# `25` Python Objects

Often you'll find yourself wanting to save more information in less space, especially if it's all related. For example:

Let's say that we want to represent cars into variables:

```Javascript
var car1Model = "corolla";
var car1Make = "Toyota";
var car1Color = "green";
var car1Year = 2015;

var car2Model = "santa fe";
var car2Make = "Hyundai";
var car2Color = "purple";
var car2Year = 2013;
//... (you get the idea)
```py
car_1_Model = "corolla"
car_1_Make = "Toyota"
car_1_Color = "green"
car_1_Year = 2015

car_2_Model = "santa fe"
car_2_Make = "Hyundai"
car_2_Color = "purple"
car_2_Year = 2013
#... (you get the idea)
```

There's an optimized approach to this, it is called Objects. Objects are a type of variable that contains information (other variables) in a key: value manner.

So if we want to translate (and optimize) the variables from the car into an Object, we do:

```js
var car1 = { model: "corolla", make: "toyota", color: "green", year: 2015};
```py
class ClassName:
def __init__():
self.model = "Corolla"
self.make = "Toyota"
self.color = "Green"
self.year = "2015"

```

You can see the key: value separated by a comma.

And for us (developers) to read it easier we write it like this:

```js
var car1 = {
model: "corolla",
make: "toyota",
color: "green",
year: 2015
};

```
Looks like a function, right? But it's not.

Now we are storing information into a more organized way, and if we want to get that information we can do:
Expand Down Expand Up @@ -70,8 +63,8 @@ var family = {
```
So, if on this scenario if we want to know the name of the first member of the Doe family we do:

```js
console.log(family.members[0].name);
```py
print(family.members[0].name);
```

Or the 3rd lucky number of the significant other of the second member of Doe's family:
Expand All @@ -82,12 +75,8 @@ console.log( family.members[1].significant_other.lucky_numbers[2]);

Easy stuff :)
## 📝 Instructions:
1. Programmatically, change the fourth lucky number of John Doe to 33 (use a command, don't manually change the code)
2. Programmatically, create a new person and add it to the family object. Jimmy Doe, 13, male, lucky numbers: 1, 2, 3, 4; significant other: null. (use a command, don't manually change the code)
3. Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family.
1. **1** Programmatically, change the fourth lucky number of John Doe to 33 (use a command, don't manually change the code)
2. **2** Programmatically, create a new person and add it to the family object. Jimmy Doe, 13, male, lucky numbers: 1, 2, 3, 4; significant other: null. (use a command, don't manually change the code)
3. **3** Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family.

## 💡 Hint:

- You can get each array of lucky numbers from each person object inside the family object.
- Once you get each array just loop over it adding every element (like we've been doing so far). And then add each sum of the 3 family members.
- Null is also an object.
51 changes: 51 additions & 0 deletions exercises/25-Python-Objects/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class Person:
name = "John"
lastname = "Doe"
age = 35
gender = "male"
lucky_numbers = [ 7, 11, 13, 17]


class Person_2:
name = "Jane"
lastname = "Doe"
age = 38
gender = "female"
lucky_numbers = [ 2, 4, 6, 8]


# STEP 1 Change the fourth lucky number of John Doe to 33

Person.lucky_numbers[3] = 33

# STEP 2 Create Little Jimmy's object

class Person_3:
name = "Jimmy"
lastname = "Doe"
age = 13
gender = "female"
lucky_numbers = [ 1, 2, 3, 4]
significant_other = None

class Family:
lastname = "Doe"
members = [Person, Person_2] #Array of objects, don't forget to add Jimmy

# STEP 3 Add Jimmy to Family object

Family.members.append(Person_3)

def add_allFamilyLuckyNumbers(an_array):
sum_ofAllLuckyNumbers = 0 # sum_ofAllLuckyNumbers is a number, the sum of all lucky numbers.
temp = 0
for i in Family.members:
for x in i.lucky_numbers:
sum_ofAllLuckyNumbers += x

return sum_ofAllLuckyNumbers

print(add_allFamilyLuckyNumbers(Family.members)) #Step 3



29 changes: 27 additions & 2 deletions exercises/25-Python-Objects/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@

# from app import my_function
import pytest
import app
import os
import re

@pytest.mark.it('Your code needs to print hello on the console')
@pytest.mark.it("1. You should not delete or change the existing code")
def test_existing_code():
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
content = f.readlines()
content = [x.strip() for x in content]
print("@@@@",content)

original_input = [
r"class Person:",
r"(\s*)name = \"John\"",
r"(\s*)lastname = \"Doe\"",
r"(\s*)age = 35",
r"(\s*)gender = \"male\"",
r"(\s*)lucky_numbers = \[ 7, 11, 13, 17]"
]
print("$$$$$$",[i for i, j in zip(original_input, content) if i == j ])


# regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);"
# assert re.match(regex, content[(len(content)-1)])


@pytest.mark.it('Your code needs to print the correct sum on the console')
def test_for_file_output(capsys):
captured = buffer.getvalue()
assert captured == "hello\n" #add \n because the console jumps the line on every print
assert captured == str(94)+'\n'

# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console')
# def test_for_function_output(capsys):
Expand Down