From b095830cbdddd92b11205fb7358a9f93afb4b71f Mon Sep 17 00:00:00 2001 From: bailey Date: Thu, 8 Jun 2017 15:50:47 -0500 Subject: [PATCH 1/2] dojofiles --- bailey_wiseman/dojofiles/OOP/animal.py | 60 ++++++++++++++ bailey_wiseman/dojofiles/OOP/bike.py | 29 +++++++ bailey_wiseman/dojofiles/OOP/calls/calls.py | 59 ++++++++++++++ bailey_wiseman/dojofiles/OOP/car.py | 32 ++++++++ bailey_wiseman/dojofiles/OOP/hospital.py | 63 +++++++++++++++ bailey_wiseman/dojofiles/OOP/mathdojo.py | 22 ++++++ bailey_wiseman/dojofiles/OOP/product.py | 53 +++++++++++++ .../dojofiles/python/checkerboard.py | 24 ++++++ bailey_wiseman/dojofiles/python/coin_toss.py | 17 ++++ .../dojofiles/python/compare_arrays.py | 46 +++++++++++ .../dojofiles/python/dictionary_basics.py | 23 ++++++ .../dojofiles/python/filter_type.py | 48 ++++++++++++ .../dojofiles/python/find_characters.py | 22 ++++++ .../dojofiles/python/fun_with_functions.py | 70 +++++++++++++++++ .../dojofiles/python/list_to_dict.py | 19 +++++ .../dojofiles/python/multiples_sum_avg.py | 45 +++++++++++ .../dojofiles/python/multiplication_table.py | 14 ++++ bailey_wiseman/dojofiles/python/names.py | 71 +++++++++++++++++ .../dojofiles/python/scores_and_grades.py | 19 +++++ bailey_wiseman/dojofiles/python/stars.py | 33 ++++++++ .../dojofiles/python/string_and_list.py | 78 +++++++++++++++++++ bailey_wiseman/dojofiles/python/tuples.py | 21 +++++ bailey_wiseman/dojofiles/python/type_list.py | 57 ++++++++++++++ 23 files changed, 925 insertions(+) create mode 100644 bailey_wiseman/dojofiles/OOP/animal.py create mode 100644 bailey_wiseman/dojofiles/OOP/bike.py create mode 100644 bailey_wiseman/dojofiles/OOP/calls/calls.py create mode 100644 bailey_wiseman/dojofiles/OOP/car.py create mode 100644 bailey_wiseman/dojofiles/OOP/hospital.py create mode 100644 bailey_wiseman/dojofiles/OOP/mathdojo.py create mode 100644 bailey_wiseman/dojofiles/OOP/product.py create mode 100644 bailey_wiseman/dojofiles/python/checkerboard.py create mode 100644 bailey_wiseman/dojofiles/python/coin_toss.py create mode 100644 bailey_wiseman/dojofiles/python/compare_arrays.py create mode 100644 bailey_wiseman/dojofiles/python/dictionary_basics.py create mode 100644 bailey_wiseman/dojofiles/python/filter_type.py create mode 100644 bailey_wiseman/dojofiles/python/find_characters.py create mode 100644 bailey_wiseman/dojofiles/python/fun_with_functions.py create mode 100644 bailey_wiseman/dojofiles/python/list_to_dict.py create mode 100644 bailey_wiseman/dojofiles/python/multiples_sum_avg.py create mode 100644 bailey_wiseman/dojofiles/python/multiplication_table.py create mode 100644 bailey_wiseman/dojofiles/python/names.py create mode 100644 bailey_wiseman/dojofiles/python/scores_and_grades.py create mode 100644 bailey_wiseman/dojofiles/python/stars.py create mode 100644 bailey_wiseman/dojofiles/python/string_and_list.py create mode 100644 bailey_wiseman/dojofiles/python/tuples.py create mode 100644 bailey_wiseman/dojofiles/python/type_list.py diff --git a/bailey_wiseman/dojofiles/OOP/animal.py b/bailey_wiseman/dojofiles/OOP/animal.py new file mode 100644 index 0000000..0dcba4a --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/animal.py @@ -0,0 +1,60 @@ +class animal(object): + def __init__(self, name, health): + self.name = name + self.health = health + + def display(self): + print 'Hit Points...', self.health + print '' + return self + + def walk(self): + print 'Walking...' + self.health -= 1 + return self + + def run(self): + print 'Running...' + self.health -= 5 + return self + +animal1 = animal('adsd', 100) +animal1.walk().walk().walk().run().run().display() + +class dog(animal): + def __init__(self, name, health): + super(dog, self).__init__(name, health) + self.name = name + self.health = health + + def pet(self): + print 'Petting...' + self.health += 5 + return self + +dog1 = dog('spot', 150) +dog1.walk().walk().pet().run().display() + +class dragon(animal): + def __init__(self, name, health): + super(dragon, self).__init__(name, health) + + def fly(self): + print 'Flying...' + self.health -= 10 + return self + +dragon1 = dragon('ajis', 170) +dragon1.fly().fly().fly().display() + +class bear(animal): + def __init__(self, name, health): + super(bear, self).__init__(name, health) + + def climb(self): + print 'Climbing...' + self.health -= 15 + return self + +bear1 = bear('misha', 800) +bear1.walk().walk().walk().climb().climb().climb().climb().display() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/OOP/bike.py b/bailey_wiseman/dojofiles/OOP/bike.py new file mode 100644 index 0000000..d90f164 --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/bike.py @@ -0,0 +1,29 @@ +class bike(object): + def __init__(self, price, max_speed, miles=0): + self.price = price + self.max_speed = max_speed + self.miles = miles + + def display(self): + print 'Price:...', self.price, 'Max_Speed:...', self.max_speed, 'Miles:...', self.miles + return self + + def ride(self): + print 'Riding...' + self.miles += 10 + return self + + def reverse(self): + if self.miles == 0: + print 'Already at zero! Cannot reverse any further!...' + else: + print 'Reversing...' + self.miles -= 5 + return self + +instance1 = bike('200$', '30mph') +instance2 = bike('400$', '42mph') +instance3 = bike('900$', '51mph') +instance1.ride().ride().ride().reverse().display() +instance2.ride().ride().reverse().reverse().display() +instance3.reverse().reverse().reverse().display() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/OOP/calls/calls.py b/bailey_wiseman/dojofiles/OOP/calls/calls.py new file mode 100644 index 0000000..6fbc281 --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/calls/calls.py @@ -0,0 +1,59 @@ +class Call(object): + def __init__(self, callid, name, phone, time, purpose): + self.callid = callid + self.name = name + self.phone = phone + self.time = time + self.purpose = purpose + + def display(self): + print 'Caller-ID :', self.callid + print 'Name :', self.name + print 'Phone# :', self.phone + print 'Call-time :', self.timeCall + print 'Purpose :', self.purpose + print '' + return self + + def __str__(self): + return "Callid: {}, Name: {}, Phone: {}, Time: {}, Purpose: {}".format( + self.callid, + self.name, + self.phone, + self.time, + self.purpose + ) + +class Center(object): + def __init__(self): + self.data = [] + self.queue = 0 + + def add_call(self, callid, name, phone, time, purpose): + print 'added call...' + call = Call(callid, name, phone, time, purpose) + self.data.append(call) + return self + + def remove_call(self): + self.data.pop(0) + print 'removed call...' + return self + + def info(self): + for call in center.data: + self.queue += 1 + print 'queue:', self.queue + return self + +center = Center() +center.add_call(1, 'joe', '214-667-4567', 1330, 'finance') +center.add_call(2, 'mary-ann', '214-869-1300', 1332, 'tech support') +center.add_call(3, 'alex', '543-443-7492', 1332, 'finance') +center.add_call(4, 'sin', '324-437-4531', 1335, 'n/a') +center.add_call(5, 'chris', '622-096-2544', 1336, 'tech support') + +center.info().remove_call().info() +for call in center.data: + print call + diff --git a/bailey_wiseman/dojofiles/OOP/car.py b/bailey_wiseman/dojofiles/OOP/car.py new file mode 100644 index 0000000..70aa3f0 --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/car.py @@ -0,0 +1,32 @@ +class car(object): + def __init__(self, price, speed, fuel, mileage, tax=1.12): + self.price = price + self.speed = speed + self.fuel = fuel + self.mileage = mileage + self.tax = tax + if self.price > 10000: + self.tax = (1.15) + + def display(self): + print 'Price:...', self.price + print 'Speed:...', self.speed, 'MPH' + print 'Fuel:...', self.fuel + print 'Mileage:...', self.mileage, 'MPG' + print 'Tax:...', self.tax + print '' + return self + +car1 = car(8000, 40, 'empty', 25) +car2 = car(18000, 80, 'low', 17) +car3 = car(3000, 20, 'empty', 13) +car4 = car(28000, 120, 'full', 20) +car5 = car(9900, 50, 'low', 22) +car6 = car(14200, 55, 'empty', 15) + +car1.display() +car2.display() +car3.display() +car4.display() +car5.display() +car6.display() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/OOP/hospital.py b/bailey_wiseman/dojofiles/OOP/hospital.py new file mode 100644 index 0000000..25eef72 --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/hospital.py @@ -0,0 +1,63 @@ +class Patient(object): + def __init__(self, p_id, name, allergies, bed=[]): + self.p_id = p_id + self.name = name + self.allergies = allergies + self.bed = bed + self.patient_info = {'p_id': self.p_id, 'name': self.name, 'allergies': self.allergies, 'bed': self.bed,} + + def __str__(self): + return "p_id: {}, Name: {}, allergies: {}, bed: {}".format( + self.p_id, + self.name, + self.allergies, + self.bed, + ) + +class Hospital(object): + def __init__(self, building, capacity): + self.info = [] + self.building = building + self.capacity = capacity + self.myid = [] + + def admit(self, p_id, name, allergies, bed): + patient = Patient(p_id, name, allergies, bed) + print 'admited patient {}, {}'.format(name, p_id) + print '' + self.info.append(patient) + self.myid.append(p_id) + return self + + def discharge(self, p_id): + print self.myid + if p_id == self.myid: + self.info.pop(patient) + self.myid.pop(p_id) + print self.myid + print '' + print 'removed patient', self.info + print '' + self.capacity += 1 + return self + + def display(self): + print 'Building: {}, Max Capacity: {}'.format(self.building, self.capacity) + print '' + for i in self.info: + print 'patient info:', i + return self + +hospital = Hospital('st.johns', 5) + +hospital.admit(2, 'jack', 'penicillin', [1]) +hospital.admit(3, 'mike', 'asprin', [2]) +hospital.admit(4, 'doug', 'penicillin', [3]) +hospital.admit(5, 'louise', 'latex', [4]) +hospital.admit(6, 'malley', 'penicillin, latex, oxiodants', [5]) + +hospital.display() + +hospital.discharge(1) + +hospital.display() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/OOP/mathdojo.py b/bailey_wiseman/dojofiles/OOP/mathdojo.py new file mode 100644 index 0000000..dcf1362 --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/mathdojo.py @@ -0,0 +1,22 @@ +class mathdojo(object): + def __init__(self, mysum=0): + self.mysum = mysum + + + def add(self, *args): + for i in args: + if type(i) == int: + self.mysum += i + return self + + def subtract(self, *args): + for i in args: + if type(i) == int: + self.mysum -= i + return self + def result(self): + print 'SUM...', self.mysum + return self + +md = mathdojo() +md.add(2).add(2, 5).subtract(3, 2).result() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/OOP/product.py b/bailey_wiseman/dojofiles/OOP/product.py new file mode 100644 index 0000000..4bede4c --- /dev/null +++ b/bailey_wiseman/dojofiles/OOP/product.py @@ -0,0 +1,53 @@ +class product(object): + def __init__(self, price, item, weight, brand, cost, status='For Sale'): + self.price = price + self.item = item + self.weight = weight + self.brand = brand + self.cost = cost + self.status = status + + def display(self): + print 'Price:...', self.price + print 'Item:...', self.item + print 'Weight:...', self.weight + print 'Brand:...', self.brand + print 'Cost:...', self.cost + print 'Status:...', self.status + print '' + + return self + + def sell(self): + self.status = 'Sold' + + return self + + def tax(self): + self.price = self.price * 1.08 + print 'Price after tax:...', self.price + return self + + def itemreturn(self, refund): + if refund == 'defective': + self.status = 'defective' + self.price = 0 + elif refund == 'like_new': + self.status = 'For Sale' + elif refund == 'used': + self.status = 'used' + self.price = self.price * 0.8 + + return self + +product1 = product(200, 'Kayak', '85lbs', 'Alqui', 200) +product2 = product(20, 'Teapot', '5lbs', 'Sern', 20) +product3 = product(2000, 'Office Chair', '15lbs', 'Office Mate', 2000) +product4 = product(60, 'SunRoof', '30lbs', 'Shade Masters', 60) +product5 = product(180, 'Monitor', '12lbs', 'Hoffs', 180) + +product1.tax().sell().display() +product2.itemreturn('defective').display() +product3.tax().sell().display() +product4.itemreturn('like_new').display() +product5.itemreturn('used').display() diff --git a/bailey_wiseman/dojofiles/python/checkerboard.py b/bailey_wiseman/dojofiles/python/checkerboard.py new file mode 100644 index 0000000..6ca175a --- /dev/null +++ b/bailey_wiseman/dojofiles/python/checkerboard.py @@ -0,0 +1,24 @@ +# Assignment: Checkerboard +# Write a program that prints a 'checkerboard' pattern to the console. + +# Your program should require no input and produce console output that looks like so: + +# * * * * +# * * * * +# * * * * +# * * * * +# * * * * +# * * * * +# * * * * +# * * * * +# Copy +# Each star or space represents a square. On a traditional checkerboard you'll see alternating squares of red or black. +# In our case we will alternate stars and spaces. The goal is to repeat a process several times. This should make you think of looping. + +def checkers(pattern1, pattern2): + for i in range(0, 100): + if i % 2 != 0: + print(pattern1) + else: + print(pattern2) +checkers('* * * *', ' * * * *') diff --git a/bailey_wiseman/dojofiles/python/coin_toss.py b/bailey_wiseman/dojofiles/python/coin_toss.py new file mode 100644 index 0000000..52f251e --- /dev/null +++ b/bailey_wiseman/dojofiles/python/coin_toss.py @@ -0,0 +1,17 @@ +import random + +def start(myrange): + tails = 0 + heads = 0 + total = heads + tails + for i in myrange: + flip = random.randrange(1, 3) + if flip == 1: + tails += 1 + total = heads + tails + print('Attempt #', total, 'out of', len(myrange), 'Throwing coin... It is Tails!...', 'Got', heads, 'Head(s) so far and', tails, 'Tail(s) so far!') + elif flip == 2: + heads += 1 + total = heads + tails + print('Attempt #', total, 'out of', len(myrange), 'Throwing coin... It is Heads!...', 'Got', heads, 'Head(s) so far and', tails, 'Tail(s) so far!') +start(range(0, 5000)) \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/compare_arrays.py b/bailey_wiseman/dojofiles/python/compare_arrays.py new file mode 100644 index 0000000..97ec3fa --- /dev/null +++ b/bailey_wiseman/dojofiles/python/compare_arrays.py @@ -0,0 +1,46 @@ +# Assignment: Compare Arrays +# Write a program that compares two lists and prints a message depending on if the inputs are identical or not. + +# Your program should be able to accept and compare two lists: list_one and list_two. If both lists are identical print "The lists are the same". If they are not identical print "The lists are not the same." Try the following test cases for lists one and two: + +# list_one = [1,2,5,6,2] +# list_two = [1,2,5,6,2] +# Copy +# list_one = [1,2,5,6,5] +# list_two = [1,2,5,6,5,3] +# Copy +# list_one = [1,2,5,6,5,16] +# list_two = [1,2,5,6,5] +# Copy +# list_one = ['celery','carrots','bread','milk'] +# list_two = ['celery','carrots','bread','cream'] + +def clone(mylist_1, mylist_2): + if (type(mylist_1) == list and type(mylist_2) == list): + print ('Both Are List!...') + print(mylist_1) + print(mylist_2) + if (len(mylist_1) == len(mylist_2)): + print ('Length is Same!...') + print(mylist_1) + print(mylist_2) + for x,y in zip(mylist_1, mylist_2): + if x != y: + print ('ERROR: List values differ!...') + print(mylist_1) + print(mylist_2) + return False + print ('List are identical!...') + print(mylist_1) + print(mylist_2) + else: + print ('ERROR: Lengths differ!...') + print(mylist_1) + print(mylist_2) + return False + else: + print ('ERROR: One or Both are not list!...') + print(mylist_1) + print(mylist_2) + return False +clone() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/dictionary_basics.py b/bailey_wiseman/dojofiles/python/dictionary_basics.py new file mode 100644 index 0000000..ee960a8 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/dictionary_basics.py @@ -0,0 +1,23 @@ +# Assignment: Making and Reading from Dictionaries +# Create a dictionary containing some information about yourself. The keys should include name, age, country of birth, favorite language. + +# Write a function that will print something like the following as it executes: + +# My name is Anna +# My age is 101 +# My country of birth is The United States +# My favorite language is Python + + + +def basics(): + + thisdict = { + 'name': 'bailey', + 'age': '21', + 'COB': 'U.S.A', + 'language': 'python' + } + for key,data in thisdict.items(): + print (key, data) +basics() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/filter_type.py b/bailey_wiseman/dojofiles/python/filter_type.py new file mode 100644 index 0000000..eb22d89 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/filter_type.py @@ -0,0 +1,48 @@ +# Assignment: Filter by Type +# Write a program that, given some value, tests that value for its type. Here's what you should do for each type: + +# Integer +# If the integer is greater than or equal to 100, print "That's a big number!" If the integer is less than 100, print "That's a small number" + +# String +# If the string is greater than or equal to 50 characters print "Long sentence." If the string is shorter than 50 characters print "Short sentence." + +# List +# If the length of the list is greater than or equal to 10 print "Big list!" If the list has fewer than 10 values print "Short list." + +# Test your program using these examples: + +# sI = 45 +# mI = 100 +# bI = 455 +# eI = 0 +# spI = -23 +# sS = "Rubber baby buggy bumpers" +# mS = "Experience is simply the name we give our mistakes" +# bS = "Tell me and I forget. Teach me and I remember. Involve me and I learn." +# eS = "" +# aL = [1,7,4,21] +# mL = [3,5,7,34,3,2,113,65,8,89] +# lL = [4,34,22,68,9,13,3,5,7,9,2,12,45,923] +# eL = [] +# spL = ['name','address','phone number','social security number'] + +def filter(unknown): + if type(unknown) == list: + if len(unknown) >= 10: + print ('Big List!') + else: + print ('Small List!') + elif type(unknown) == str: + if len(unknown) >= 50: + print ('Long String!') + else: + print ('Short String!') + elif type(unknown) == int: + if unknown >= 100: + print ('Big Number!') + else: + print ('Small Number!') +filter() + + diff --git a/bailey_wiseman/dojofiles/python/find_characters.py b/bailey_wiseman/dojofiles/python/find_characters.py new file mode 100644 index 0000000..71b5e29 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/find_characters.py @@ -0,0 +1,22 @@ +# Assignment: Find Characters +# Write a program that takes a list of strings and a string containing a single character, +# and prints a new list of all the strings containing that character. + +# Here's an example: + +# # input +# word_list = ['hello','world','my','name','is','Anna'] +# char = 'o' +# # output +# new_list = ['hello','world'] +# Copy +# Hint: how many loops will you need to complete this task? + +def findchar(mylist, mychar): + newlist = [] + for i in mylist: + for x in i: + if x == mychar: + newlist += [i] + print (newlist) +findchar(['hello','world','my','name','is','Anna'], 'o') \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/fun_with_functions.py b/bailey_wiseman/dojofiles/python/fun_with_functions.py new file mode 100644 index 0000000..4ff7109 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/fun_with_functions.py @@ -0,0 +1,70 @@ +# Assignment: Fun with Functions +# Create a series of functions based on the below descriptions. + +# Odd/Even: +# Create a function called odd_even that counts from 1 to 2000. +# As your loop executes have your program print the number of that iteration and specify whether it's an odd or even number. + +# Your program output should look like below: + +# Number is 1. This is an odd number. +# Number is 2. This is an even number. +# Number is 3. This is an odd number. +# ... +# Number is 2000. This is an even number. +# Copy +# Multiply: +# Create a function called 'multiply' that iterates through each value in a list +# (e.g. a = [2, 4, 10, 16]) and returns a list where each value has been multiplied by 5. + +# The function should multiply each value in the list by the second argument. For example, let's say: + +# a = [2,4,10,16] +# Copy +# Then: + +# b = multiply(a, 5) +# print b +# Copy +# Should print [10, 20, 50, 80 ]. + +# Hacker Challenge: +# Write a function that takes the multiply function call as an argument. +# Your new function should return the multiplied list as a two-dimensional list. +# Each internal list should contain the number of 1's as the number in the original list. Here's an example: + +# def layered_multiples(arr) +# # your code here +# return new_array +# x = layered_multiples(multiply([2,4,5],3)) +# print x +# # output +# >>>[[1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]] + + +def oddeven(myrange): + for i in myrange: + if i % 2 == 0: + print (i, 'even') + else: + print (i, 'odd') +oddeven(range(1, 2001)) + + +def multiply(mylist): + newlist = [] + for i in mylist: + newlist += [i*5] + print(newlist) +multiply([1,2,3,4,5]) + + +def layered(mylist): + newlist = [] + for i in mylist: + glue = [] + for x in range(0, i): + glue.append(1) + newlist += [glue] + print (newlist) +layered([1,2,3,4,5]) \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/list_to_dict.py b/bailey_wiseman/dojofiles/python/list_to_dict.py new file mode 100644 index 0000000..eefc30e --- /dev/null +++ b/bailey_wiseman/dojofiles/python/list_to_dict.py @@ -0,0 +1,19 @@ +# Assignment: Making Dictionaries +# Create a function that takes in two lists and creates a single dictionary where the first list contains keys and the second values. Assume the lists will be of equal length. + +# Your first function will take in two lists containing some strings. Here are two example lists: + +# name = ["Anna", "Eli", "Pariece", "Brendan", "Amy", "Shane", "Oscar"] +# favorite_animal = ["horse", "cat", "spider", "giraffe", "ticks", "dolphins", "llamas"] +# Copy +# Here's some help starting your function. + +# def make_dict(arr1, arr2): +# new_dict = {} +# # your code here +# return new_dict + +def mydict(list1, list2): + new_dict = zip(list1, list2) + print dict(new_dict) +mydict(["Anna", "Eli", "Pariece", "Brendan", "Amy", "Shane", "Oscar"], ["horse", "cat", "spider", "giraffe", "ticks", "dolphins", "llamas"]) \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/multiples_sum_avg.py b/bailey_wiseman/dojofiles/python/multiples_sum_avg.py new file mode 100644 index 0000000..53cf633 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/multiples_sum_avg.py @@ -0,0 +1,45 @@ +# Assignment: Multiples, Sum, Average +# This assignment has several parts. +# All of your code should be in one file that is well commented to indicate what each block of code is doing and which problem you are solving. +# Don't forget to test your code as you go! + + + +# Multiples +# Part I - Write code that prints all the odd numbers from 1 to 1000. Use the for loop and don't use a list to do this exercise. + +def multiples(myrange): + for i in myrange: + if i % 2 != 0: + print (i) +multiples(range(0, 1001)) + + +# Part II - Create another program that prints all the multiples of 5 from 5 to 1,000,000. + +def million(myrange): + for i in myrange: + if i % 5 == 0: + print (i) +million(range(5, 1000000)) + +# Sum List +# Create a program that prints the sum of all the values in the list: a = [1, 2, 5, 10, 255, 3] + +def sumlist(mylist): + mysum = 0 + for i in mylist: + mysum += i + print (mysum) +sumlist([1, 2, 5, 10, 255, 3]) + +# Average List +# Create a program that prints the average of the values in the list: a = [1, 2, 5, 10, 255, 3] + +def findavg(mylist): + mysum = 0 + for i in mylist: + mysum += i + avg = (mysum/len(mylist)) + print (avg) +findavg([1, 2, 5, 10, 255, 3]) \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/multiplication_table.py b/bailey_wiseman/dojofiles/python/multiplication_table.py new file mode 100644 index 0000000..47b8753 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/multiplication_table.py @@ -0,0 +1,14 @@ +def table(): + count = 0 + x = 1 + while count < 13: + if count < 2: + x = 1 + count += 1 + print (x * 1, x * 2, x * 3, x * 4, x * 5, x * 6, x * 7, x * 8, x * 9, x * 10, x * 11, x * 12) + elif count > 1: + x += 1 + count += 1 + print (x * 1, x * 2, x * 3, x * 4, x * 5, x * 6, x * 7, x * 8, x * 9, x * 10, x * 11, x * 12) + +table() \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/names.py b/bailey_wiseman/dojofiles/python/names.py new file mode 100644 index 0000000..0f68d71 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/names.py @@ -0,0 +1,71 @@ +# Assignment: Names +# Write the following function. + +# Part I +# Given the following list: + +# students = [ +# {'first_name': 'Michael', 'last_name' : 'Jordan'}, +# {'first_name' : 'John', 'last_name' : 'Rosales'}, +# {'first_name' : 'Mark', 'last_name' : 'Guillen'}, +# {'first_name' : 'KB', 'last_name' : 'Tonel'} +# ] +# Copy +# Create a program that outputs: + +# Michael Jordan +# John Rosales +# Mark Guillen +# KB Tonel + + + +def part1(): + students = [ + {'first_name': 'Michael', 'last_name' : 'Jordan'}, + {'first_name' : 'John', 'last_name' : 'Rosales'}, + {'first_name' : 'Mark', 'last_name' : 'Guillen'}, + {'first_name' : 'KB', 'last_name' : 'Tonel'} + ] + for val in students: + print val['first_name'], val['last_name'] +part1() + +# Part II +# Now, given the following dictionary: + + + + + + +def part2(): + users = { + 'Students': [ + {'first_name': 'Michael', 'last_name' : 'Jordan'}, + {'first_name' : 'John', 'last_name' : 'Rosales'}, + {'first_name' : 'Mark', 'last_name' : 'Guillen'}, + {'first_name' : 'KB', 'last_name' : 'Tonel'} + ], + 'Instructors': [ + {'first_name' : 'Michael', 'last_name' : 'Choi'}, + {'first_name' : 'Martin', 'last_name' : 'Puryear'} + ] + } + for key,data in users.items(): + print key, data +part2() + + + +# Copy +# Create a program that prints the following format (including number of characters in each combined name): + +# Students +# 1 - MICHAEL JORDAN - 13 +# 2 - JOHN ROSALES - 11 +# 3 - MARK GUILLEN - 11 +# 4 - KB TONEL - 7 +# Instructors +# 1 - MICHAEL CHOI - 11 +# 2 - MARTIN PURYEAR - 13 \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/scores_and_grades.py b/bailey_wiseman/dojofiles/python/scores_and_grades.py new file mode 100644 index 0000000..00658f1 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/scores_and_grades.py @@ -0,0 +1,19 @@ +# Assignment: Scores and Grades +# Write a function that generates ten scores between 60 and 100. +# Each time a score is generated, your function should display what the grade is for a particular score. Here is the grade table: + +# Score: 60 - 69; Grade - D Score: 70 - 79; Grade - C Score: 80 - 89; Grade - B Score: 90 - 100; Grade - A + +import random +roll = random.randrange(60, 101) + +def scores(): + if roll > 59 and roll < 70: + print('Score:...', roll, 'Your Grade is D') + elif roll > 69 and roll < 80: + print('Score:...', roll, 'Your Grade is C') + elif roll > 79 and roll < 90: + print('Score:...', roll, 'Your Grade is B') + elif roll > 89 and roll < 101: + print('Score:...', roll, 'Your Grade is A') +scores() diff --git a/bailey_wiseman/dojofiles/python/stars.py b/bailey_wiseman/dojofiles/python/stars.py new file mode 100644 index 0000000..7a3d158 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/stars.py @@ -0,0 +1,33 @@ +# Assignment: Stars +# Write the following functions. + +# Part I +# Create a function called draw_stars() that takes a list of numbers and prints out *. + +def stars(mylist): + for i in mylist: + chain = '' + for x in range(0, i): + chain += '*' + print (chain) +stars([4, 6, 1, 3, 5, 7, 25]) + + +# Part II +# Modify the function above. Allow a list containing integers and strings to be passed to the draw_stars() function. +# When a string is passed, instead of displaying *, display the first letter of the string according to the example below. +# You may use the .lower() string method for this part. + +def first(mylist): + for i in mylist: + if type(i) == int: + chain = '' + for x in range(0, i): + chain += '*' + print (chain) + elif type(i) == str: + mystr = '' + for z in i: + mystr += i[0] + print (mystr) +first([4, "Tom", 1, "Michael", 5, 7, "Jimmy Smith"]) diff --git a/bailey_wiseman/dojofiles/python/string_and_list.py b/bailey_wiseman/dojofiles/python/string_and_list.py new file mode 100644 index 0000000..a478b3e --- /dev/null +++ b/bailey_wiseman/dojofiles/python/string_and_list.py @@ -0,0 +1,78 @@ +# Use only the built-in methods and functions from the previous tabs to do the following exercises. You will find the following methods and functions useful: + +# • .find() + +# • .replace() + +# • min() + +# • max() + +# • .sort() + +# • len() + + + +# Find and Replace +# In this string: words = "It's thanksgiving day. It's my birthday,too!" + # print the position of the first instance of the word "day". Then create a new string where the word "day" is replaced with the word "month". + +def findnreplace(mystr): + day = 'day' + month = 'month' + findit = mystr.find(day) + replc = mystr.replace(day, month) + print(mystr, findit, replc) +findnreplace("It's thanksgiving day. It's my birthday,too!") + + +# Min and Max +# Print the min and max values in a list like this one: x = [2,54,-2,7,12,98]. Your code should work for any list. + +def mymax(mylist): + compare = mylist[0] + for i in mylist: + if compare < i: + compare = i + print (compare, "max", mylist) +mymax([2,54,-2,7,12,98]) + +def mymin(mylist): + compare = mylist[0] + for i in mylist: + if compare > i: + compare = i + print (compare, "min", mylist) +mymin([2,54,-2,7,12,98]) + +# First and Last +# Print the first and last values in a list like this one: x = ["hello",2,54,-2,7,12,98,"world"]. + # Now create a new list containing only the first and last values in the original list. Your code should work for any list. + +def fandl(mylist): + first = mylist[0] + last = mylist[-1] + print ('first-value:', first, 'last-value:', last) + print (mylist) +fandl(["hello",2,54,-2,7,12,98,"world"]) + +# New List +# Start with a list like this one: x = [19,2,54,-2,7,12,98,32,10,-3,6]. Sort your list first. Then, split your list in half. + # Push the list created from the first half to position 0 of the list created from the second half. + # The output should be: [[-3, -2, 2, 6, 7], 10, 12, 19, 32, 54, 98]. Stick with it, this one is tough! + +def newlist(mylist): + mylist.sort() + print (mylist) + middle = len(mylist)/2 + print (middle) + middle = int(middle) + print (middle) + left = mylist[0:5] + print (left) + right = mylist[5:] + print (right) + stitch = left + right + print (stitch) +newlist([19,2,54,-2,7,12,98,32,10,-3,6]) \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/tuples.py b/bailey_wiseman/dojofiles/python/tuples.py new file mode 100644 index 0000000..d031acb --- /dev/null +++ b/bailey_wiseman/dojofiles/python/tuples.py @@ -0,0 +1,21 @@ +# Assignment: Dictionary in, tuples out +# Write a function that takes in a dictionary and returns a list of tuples where the first tuple item is the key and the second is the value. +# Here's an example: + +# # function input +# my_dict = { +# "Speros": "(555) 555-5555", +# "Michael": "(999) 999-9999", +# "Jay": "(777) 777-7777" +# } +# #function output +# [("Speros", "(555) 555-5555"), ("Michael", "(999) 999-9999"), ("Jay", "(777) 777-7777")] + + +my_dict = { + "Speros": "(555) 555-5555", + "Michael": "(999) 999-9999", + "Jay": "(777) 777-7777" +} + +print (my_dict.items()) \ No newline at end of file diff --git a/bailey_wiseman/dojofiles/python/type_list.py b/bailey_wiseman/dojofiles/python/type_list.py new file mode 100644 index 0000000..2da6a61 --- /dev/null +++ b/bailey_wiseman/dojofiles/python/type_list.py @@ -0,0 +1,57 @@ +# Assignment: Type List +# Write a program that takes a list and prints a message for each element in the list, +# based on that element's data type. + +# Your program input will always be a list. For each item in the list, test its data type. If the item is a string, +# concatenate it onto a new string. If it is a number, add it to a running sum. At the end of your program print the string, the number and an analysis of what the array contains. If it contains only one type, print that type, otherwise, print 'mixed'. + +# Here are a couple of test cases. Think of some of your own, too. What kind of unexpected input could you get? + +# #input +# l = ['magical unicorns',19,'hello',98.98,'world'] +# #output +# "The array you entered is of mixed type" +# "String: magical unicorns hello world" +# "Sum: 117.98" +# Copy +# # input +# l = [2,3,1,7,4,12] +# #output +# "The array you entered is of integer type" +# "Sum: 29" +# Copy +# # input +# l = ['magical','unicorns'] +# #output +# "The array you entered is of string type" +# "String: magical unicorns" + + +def typelist(mylist): + stronly = True + intonly = True + Mixed = False + mysum = 0 + mystr = '' + for i in mylist: + if type(i) == int: + mysum += i + print ('integer:..', i) + stronly = False + elif type(i) == str: + mystr += i + print ('string:..', i) + intonly = False + if stronly == True: + print ('This is a string list!...') + print ('mystr:..', mystr) + print (mylist) + elif intonly == True: + print ('this is an integer list!...') + print ('mysum:..', mysum) + print (mylist) + else: + print ('Its a mixed list!...') + print ('mysum:..', mysum, 'mystr:..', mystr) + print (mylist) +typelist(['magical unicorns',19,'hello',98.98,'world']) \ No newline at end of file From 39a907ecf7334a64357b70a1dcd1f698f6e3f2c4 Mon Sep 17 00:00:00 2001 From: bailey Date: Mon, 12 Jun 2017 16:34:26 -0500 Subject: [PATCH 2/2] added flask files --- bailey_wiseman/flask/projects_flask | 1 + 1 file changed, 1 insertion(+) create mode 160000 bailey_wiseman/flask/projects_flask diff --git a/bailey_wiseman/flask/projects_flask b/bailey_wiseman/flask/projects_flask new file mode 160000 index 0000000..0b3f7ba --- /dev/null +++ b/bailey_wiseman/flask/projects_flask @@ -0,0 +1 @@ +Subproject commit 0b3f7bad407cb09f4452fe68a44dad51ccb493fd