Skip to content

Instantly share code, notes, and snippets.

View joanita-51's full-sized avatar

NAKITYO JOANITA joanita-51

View GitHub Profile
@joanita-51
joanita-51 / mystyles2.css
Created June 30, 2022 08:28
Developing our Ecomerce static website using bootstrap and the designs from figma
.search{
background-color: #13505B;
color: #ffffff;
}
.input{
border-radius:15px;
border: 2px solid #0C7489;
background-color: #D7D9CE;
}
@joanita-51
joanita-51 / oop-classes-1.py
Created August 1, 2021 14:10
Object Oriented Programming in Python : Created a Rational class that has a rational object it prints out and a method to reduce the numerator an denominator of the rational object.
#Classes
#But this isn't the whole story. The methods and attributes of a dict don't tell us anything about key-value pairs or hashing. The full definition of an object is an object's class.
#We can define our own classes to create objects that carry out a variety of related tasks or represent information in a convenient way. Some examples we'll deal with later in the course are classes for making plots and graphs, classes for creating and analyzing tables of data, and classes for doing statistics and regression.
# let's implement a class called Rational for working with fractional numbers (e.g. 5/15). The first thing we'll need Rational to do is to be able to create a Rational object. We define how this should work with a special (hidden) method called __init__. We'll also define another special method called __repr__ that tells Python how to print out the object.
class Rational(object):
def __init__(self, numerator, denominator):
self.numerator = numerator
@joanita-51
joanita-51 / oop-objects.py
Created August 1, 2021 10:32
Object Oriented Programming in python
#Object Oriented Programming
#we can think of an object as anything we can store in a variable. We can have objects with different type. We might also call an object's type its class.
x = 42
print('%d is an object of %s' % (x, type(x))) #42 is an object of <class 'int'>
x = 'Hello world!'
print('%s is an object of %s' % (x, type(x))) #Hello world! is an object of <class 'str'>
x = {'name': 'Dylan', 'age': 26}
print('%s is an object of %s' % (x, type(x))) #{'name': 'Dylan', 'age': 26} is an object of <class 'dict'>
@joanita-51
joanita-51 / algorithms.py
Created July 31, 2021 01:28
Algorithms Day Two - Memoization and memory
#Memoization
#Often we can get a performance increase just by not recomputing things we have already computed! Let's look again at our recursive Fibonacci sequence
def fibonacci_recursive(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
@joanita-51
joanita-51 / algorithms.py
Created July 29, 2021 19:03
Algorithms Day One - Introduction & Time Complexity
#Algorithms
#An algorithm is a solution to the problem , its an abstract idea behind the code. When solving problems two steps take place
#1.Algorithm development : the instructions / steps we take to solve the problem
#2.Implementation / development: Writing the code for the algorithm .
#Whe writing algorithms we consider :
#1.Time (computational complexity) : How many instructions do we need to execute as the size of the input grows?
#2.Memory : How much memory is needed as the size of the input grows?
#3.I/O : How many reads and writes or network requests do I need to make?
#A python tuple is a very similar to a list with one major difference - Its immutable . We create a tuple using parenthesis ()
example_tuple = ('Dylan', 26, 167.6, True)
print(example_tuple)
#we can retrieve data through indexing (because a tuple is ordered), we cannot modify it (because a tuple is immutable). for clarity we should enclose tuples with (), Python will assume we want a tuple if we don't use any symbols to enclose comma separated values
another_example_tuple = 'Jill', 36, 162.3, True
print(another_example_tuple)
print(type(another_example_tuple))
#This implicit tuple comes up most often when working with functions that return multiple outputs. For example, we might have a function that returns the first and last letter of a string.
@joanita-51
joanita-51 / lists.py
Last active July 24, 2021 14:21
learning data structures day 1
# Python list can be used to store a collection of data. for example:
beans_recipe = ['Soak beans in water', 'Dissolve salt in water', 'Heat water and beans to boil', 'Drain beans when done cooking']
#We've created lists by using square brackets [] around the data we want the list to contain. We can also create lists out of variables, rather than writing in the data directly.
#Sometimes we will store information in individual variables, but often we will be working with several pieces of information that we want to group together because of their relationship or similarity. For example, if we were shopping for groceries, we could store each item we are going to buy in separate variables or we could store all of the items in one list.
grocery_a = 'chicken'
grocery_b = 'onions'
grocery_c = 'rice'
grocery_d = 'peppers'
/**
* Dates
* Show the today's date and the time using Date()
*/
console.clear();
//To return present date and time
console.log(Date());
//To return the current date
/**
* Array methods
*/
/**
* array.concat(value1, value2.........valueN)
* concatenates two or more arrays and returns a new array
* It also accepts values of different data types e.g strings, numbers etc..
*/
let districts1 = ["Kampala", "Jinja", "Mukono"];
@joanita-51
joanita-51 / JavaScript-Day10.js
Last active July 11, 2021 07:34
Strings and methods
/**
* string.substr(start[, length]) :Extracted a portion of a string beginning
* from strat and ending at the start plus length
* The return is the extrscted string/characters.
* you are rcommended to start from 0 to string.length-1
* if start is negative, the extraction begins from the end of the string
* If the start is out of bounds or greater than the string.length an empty
* string will be returned.
*
* If you don't specify the length but specify the start then the return from the sart