-
2. Object Oriented Programming
2. Object Oriented Programming
-
22
Age of Empire
<p>Object Oriented Programming (OOP) is the fifth and last core-building blocks of software. Together with the other four building blocks, you can create anything in software.</p> <p>Before we ... -
23
Fighter
<p>Let's create a class called Fighter.</p> <p>A fighter should have the following attributes:</p> <ul><li>level of 1</li><li>hp of 100</li><li>mp of 20</li><li>strength of 20</li><li>armor of 60 (t ... -
24
Deck of Cards
<p></p> <figure><img src="https://dc-s3bucket.s3.us-west-2.amazonaws.com/admin/uploads/1590531193_deck_cards.jpeg" data-image="czwuervqgzys"></figure> <p>Imagine that you're playing a card game with ... -
25
Ninja - Class Inheritance
<p>Imagine that you did have a class called Peon which had the following attributes and methods:</p> <pre>class Peon: def __init__(self): self.hp ... -
26
Useful Library Part I
<p>You decide to create several functions and make it available for others to use also.</p> <p>Say that you wanted to implement the following 5 methods for your class UsefulLibrary.</p> <ul><li><str ... -
27
Useful Library Part II
<p>Imagine that your friend wrote a useful library with hundreds of functions and put them on Github for anyone else to use.</p> <p>Imagine that the code your friend wrote is all contains in a single ... -
28
Self (chaining)
<p>Imagine that you wanted to create a library 'mathLib' such that you could do operations such as this:</p><pre>mathLib = MathLibrary() #create a new object mathLib result = mathLib.add(10).add(3,5) ... -
1. Core building blocks
1. Core building blocks
-
1
Print 1 to 100
<p>Write a function that prints numbers from 1 to 100</p> <h2>Python - Function</h2> <pre>def abc(x): # use def to create a function print(x) # use print to print/log return x # return ... -
2
Print X to Y
<p>Write a function that prints all the integer values from X to Y.</p> -
3
Print Even from X to Y
<p>Print all the even numbers from X to Y. </p> -
4
SumFrom X to Y
<p>Create a function that returns a sum of all the integers from X to Y.</p> -
5
Even Sum from X to Y
<p>Write a function that returns the sum of all the even numbers from X to Y.</p> -
6
Iterating an array
<p>Write a function that prints each value in the array.</p> <h2>Python - List</h2> <p>In Python, arrays are called lists. Here's how you can iterate through a list.</p> <pre>students = ['Mik ... -
7
Generate Array from X to Y
<p>Create a function that returns an array with 20 values. For index X to Y, have it be filled with the value of 1. For other values, have it be 0. Assume that X is less than Y and a ... -
8
Update negatives to 0
<p>Write a function that updates all the negative numbers to 0.</p> -
9
Removing negatives
<p>Create a function to return a new list where all the negative numbers are removed.</p> -
10
Countdown
<p>Create a function that accepts a number as an input. Return a new list that counts down by one, from the number (as the 0th element) down to 0 (as the last element).</p><p>For example, countd ... -
11
Values Greater than Second
<p>Write a function that accepts a list and creates a new list containing only the values from the original list that are greater than its 2nd value. Print how many values this is and then retur ... -
12
This Length That Value
<p>Write a function that accepts two integers as parameters: size and value. The function should create and return a list whose length is equal to the given size, and whose values are all the gi ... -
13
Count Positives
<p>Given a list of numbers, create a function to replace the last value with the number of positive values. Note that zero is not considered to be a positive number.</p><ul><li>Example: count_positive ... -
14
Sum Total
<p>Create a function that takes a list and returns the sum of all the values in the array.</p><ul><li>Example: sum_total([1,2,3,4]) should return 10</li><li>Example: sum_total([6,3,-2]) should return ... -
15
Average
<p>Create a function that takes a list and returns the average of all the values.</p><ul><li>Example: average([1,2,3,4]) should return 2.5</li></ul> -
16
Minimum
<p>Create a function that takes a list of numbers and returns the minimum value in the list. If the list is empty, have the function return False.</p> <ul><li>Example: minimum([37,2,1,-9]) shou ... -
17
Maximum
<p>Create a function that takes a list and returns the maximum value in the array. If the list is empty, have the function return False.</p><ul><li>Example: maximum([37,2,1,-9]) should return 37 ... -
18
Working with a dictionary (part I)
<p>A dictionary in Python is where we can store key/value pairs.</p> <p>For example,</p> <pre>student = { "name": "Jane Doe", "birth_year": 1990 } print(student["name"]) #prints "Jane Doe" stude ... -
19
Working with a dictionary (part II)
<p>Previously you were given a dictionary such as below:</p> <pre>staff_directory = { "managers": [ "Michael", "John" ], "employees": [ "Howard", "Lori", "Elijah" ], "owner": [ "Bob", ... -
20
Working with a dictionary (part III)
<p>Continuing from the previous challenge, modify the function so that, if given the following dictinoary</p> <pre>{ "managers": [ "Michael", "John" ], "employees": [ "Howard", "Lori", "Eli ... -
21
Ultimate Analysis
<p>Create a function that takes a list and returns a dictionary that has the sumTotal, average, minimum, maximum, and length of the list.</p><ul><li>Example: ultimate_analysis([37,2,1,-9]) should retu ... -
3. Data Structures
3. Data Structures
-
29
Strings
<p>Note the following.</p> <pre>class Animal: def __init__(self): pass a = Animal() b = Animal() print(type(a)) # <class 'Animal'> print(type(b)) # <class 'Animal'> ... -
30
Tuples I
<p>Tuples are very similar to arrays/lists except that they are are unchangeable or immutable.</p> <p>Here are some examples of tuples:</p> <pre>cars = ("Honda", "GM", "Dodge", "Hyundai") print(car ...