From 0ea8c393f30377caa7b2e3fd0153c459a3bb5c36 Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Sun, 7 Oct 2018 22:04:02 -0400 Subject: [PATCH 1/7] Added base files for each exercise Added base files for each python exercise in coindgbat, along with the script used to generate each file. --- codingbat_exercise_scraper.py | 73 +++++++++++++++++++++++++++++++++++ list-1/common_end.py | 9 +++++ list-1/has23.py | 9 +++++ list-1/make_ends.py | 9 +++++ list-1/make_pi.py | 7 ++++ list-1/max_end3.py | 9 +++++ list-1/middle_way.py | 9 +++++ list-1/reverse3.py | 9 +++++ list-1/rotate_left3.py | 9 +++++ list-1/same_first_last.py | 9 +++++ list-1/sum2.py | 9 +++++ list-1/sum3.py | 9 +++++ list-2/big_diff.py | 9 +++++ list-2/centered_average.py | 9 +++++ list-2/has22.py | 9 +++++ list-2/sum13.py | 9 +++++ list-2/sum67.py | 9 +++++ logic-1/alarm_clock.py | 9 +++++ logic-1/caught_speeding.py | 9 +++++ logic-1/date_fashion.py | 9 +++++ logic-1/in1to10.py | 9 +++++ logic-1/love6.py | 9 +++++ logic-1/near_ten.py | 9 +++++ logic-1/sorta_sum.py | 9 +++++ logic-1/squirrel_play.py | 9 +++++ logic-2/close_far.py | 9 +++++ logic-2/lucky_sum.py | 9 +++++ logic-2/make_bricks.py | 9 +++++ logic-2/make_chocolate.py | 9 +++++ logic-2/no_teen_sum.py | 9 +++++ logic-2/round_sum.py | 9 +++++ string-1/combo_string.py | 9 +++++ string-1/extra_end.py | 9 +++++ string-1/first_half.py | 9 +++++ string-1/first_two.py | 9 +++++ string-1/left2.py | 9 +++++ string-1/make_abba.py | 9 +++++ string-1/make_out_word.py | 9 +++++ string-1/make_tags.py | 9 +++++ string-1/non_start.py | 9 +++++ string-1/without_end.py | 9 +++++ string-2/cat_dog.py | 9 +++++ string-2/count_code.py | 9 +++++ string-2/count_hi.py | 9 +++++ string-2/end_other.py | 9 +++++ string-2/xyz_there.py | 9 +++++ warmup-1/diff21.py | 9 +++++ warmup-1/front3.py | 9 +++++ warmup-1/front_back.py | 9 +++++ warmup-1/makes10.py | 9 +++++ warmup-1/missing_char.py | 9 +++++ warmup-1/monkey_trouble.py | 9 +++++ warmup-1/near_hundred.py | 9 +++++ warmup-1/not_string.py | 9 +++++ warmup-1/parrot_trouble.py | 9 +++++ warmup-1/pos_neg.py | 9 +++++ warmup-1/sum_double.py | 9 +++++ warmup-2/array123.py | 9 +++++ warmup-2/array_count9.py | 9 +++++ warmup-2/array_front9.py | 9 +++++ warmup-2/front_times.py | 9 +++++ warmup-2/last2.py | 9 +++++ warmup-2/string_bits.py | 9 +++++ warmup-2/string_match.py | 9 +++++ warmup-2/string_splosion.py | 9 +++++ 65 files changed, 647 insertions(+) create mode 100644 codingbat_exercise_scraper.py create mode 100644 list-1/common_end.py create mode 100644 list-1/has23.py create mode 100644 list-1/make_ends.py create mode 100644 list-1/make_pi.py create mode 100644 list-1/max_end3.py create mode 100644 list-1/middle_way.py create mode 100644 list-1/reverse3.py create mode 100644 list-1/rotate_left3.py create mode 100644 list-1/same_first_last.py create mode 100644 list-1/sum2.py create mode 100644 list-1/sum3.py create mode 100644 list-2/big_diff.py create mode 100644 list-2/centered_average.py create mode 100644 list-2/has22.py create mode 100644 list-2/sum13.py create mode 100644 list-2/sum67.py create mode 100644 logic-1/alarm_clock.py create mode 100644 logic-1/caught_speeding.py create mode 100644 logic-1/date_fashion.py create mode 100644 logic-1/in1to10.py create mode 100644 logic-1/love6.py create mode 100644 logic-1/near_ten.py create mode 100644 logic-1/sorta_sum.py create mode 100644 logic-1/squirrel_play.py create mode 100644 logic-2/close_far.py create mode 100644 logic-2/lucky_sum.py create mode 100644 logic-2/make_bricks.py create mode 100644 logic-2/make_chocolate.py create mode 100644 logic-2/no_teen_sum.py create mode 100644 logic-2/round_sum.py create mode 100644 string-1/combo_string.py create mode 100644 string-1/extra_end.py create mode 100644 string-1/first_half.py create mode 100644 string-1/first_two.py create mode 100644 string-1/left2.py create mode 100644 string-1/make_abba.py create mode 100644 string-1/make_out_word.py create mode 100644 string-1/make_tags.py create mode 100644 string-1/non_start.py create mode 100644 string-1/without_end.py create mode 100644 string-2/cat_dog.py create mode 100644 string-2/count_code.py create mode 100644 string-2/count_hi.py create mode 100644 string-2/end_other.py create mode 100644 string-2/xyz_there.py create mode 100644 warmup-1/diff21.py create mode 100644 warmup-1/front3.py create mode 100644 warmup-1/front_back.py create mode 100644 warmup-1/makes10.py create mode 100644 warmup-1/missing_char.py create mode 100644 warmup-1/monkey_trouble.py create mode 100644 warmup-1/near_hundred.py create mode 100644 warmup-1/not_string.py create mode 100644 warmup-1/parrot_trouble.py create mode 100644 warmup-1/pos_neg.py create mode 100644 warmup-1/sum_double.py create mode 100644 warmup-2/array123.py create mode 100644 warmup-2/array_count9.py create mode 100644 warmup-2/array_front9.py create mode 100644 warmup-2/front_times.py create mode 100644 warmup-2/last2.py create mode 100644 warmup-2/string_bits.py create mode 100644 warmup-2/string_match.py create mode 100644 warmup-2/string_splosion.py diff --git a/codingbat_exercise_scraper.py b/codingbat_exercise_scraper.py new file mode 100644 index 0000000..8eef860 --- /dev/null +++ b/codingbat_exercise_scraper.py @@ -0,0 +1,73 @@ +""" +This script gets all the exercises in codingbat and creates a base file in the appropriate folder to edit. + +Author: Ha Min Ko +""" + + +import requests, bs4 +import os +from os.path import exists + +urlbase = 'https://codingbat.com' +url = urlbase + '/python' + +cwd = os.getcwd() +res = requests.get(url) +res.raise_for_status() + +html = bs4.BeautifulSoup(res.text, features='html.parser') + +# We get the link for each main page. +for link in html.select('div[class=summ] > a'): + name = link.text.lower() + folder = cwd + '\\' + name + os.chdir(folder) + + url1 = urlbase + link['href'] + + res1 = requests.get(url1) + html1 = bs4.BeautifulSoup(res1.text, features='html.parser') + + # We get the link for each exercise. + for link1 in html1.select('td[width="200"] > a'): + # print(link1.text) + name1 = link1.text + + url2 = urlbase + link1['href'] + res2 = requests.get(url2) + + html2 = bs4.BeautifulSoup(res2.text, features='html.parser') + # print(html2) + + title = name1 + '.py' + + # Check if file already exists. + if (exists(title)): + print(title, 'exists already.') + else: + functiondefiner = html2.select('div[id=ace_div]')[0].text.strip() + functiondescription = html2.select('p[class=max2]')[0].text.strip() + functiontest = [] + for br in html2.find_all('br'): + following = br.nextSibling + if name1 in following: + functiontest.append(following) + + # Create a file that can be written to. + print('Creating file', title, 'in folder', name ) + outputfile = open(title, 'w') + + # Write data to the file: + outputfile.write(functiondefiner) + outputfile.write('\n\t"""') + outputfile.write('\n\t' + functiondescription) + outputfile.write('\n\t"""') + outputfile.write('\n\tpass') + outputfile.write('\n') + for test in functiontest: + test = test.split('→')[0].strip() + outputfile.write('\nprint(' + test + ')') + + # Close the file after writing to it + outputfile.close() \ No newline at end of file diff --git a/list-1/common_end.py b/list-1/common_end.py new file mode 100644 index 0000000..95a3069 --- /dev/null +++ b/list-1/common_end.py @@ -0,0 +1,9 @@ +def common_end(a, b): + """ + Given 2 arrays of ints, a and b, return True if they have the same first element or they have the same last element. Both arrays will be length 1 or more. + """ + pass + +print(common_end([1, 2, 3], [7, 3])) +print(common_end([1, 2, 3], [7, 3, 2])) +print(common_end([1, 2, 3], [1, 3])) \ No newline at end of file diff --git a/list-1/has23.py b/list-1/has23.py new file mode 100644 index 0000000..8584ac4 --- /dev/null +++ b/list-1/has23.py @@ -0,0 +1,9 @@ +def has23(nums): + """ + Given an int array length 2, return True if it contains a 2 or a 3. + """ + pass + +print(has23([2, 5])) +print(has23([4, 3])) +print(has23([4, 5])) \ No newline at end of file diff --git a/list-1/make_ends.py b/list-1/make_ends.py new file mode 100644 index 0000000..9700981 --- /dev/null +++ b/list-1/make_ends.py @@ -0,0 +1,9 @@ +def make_ends(nums): + """ + Given an array of ints, return a new array length 2 containing the first and last elements from the original array. The original array will be length 1 or more. + """ + pass + +print(make_ends([1, 2, 3])) +print(make_ends([1, 2, 3, 4])) +print(make_ends([7, 4, 6, 2])) \ No newline at end of file diff --git a/list-1/make_pi.py b/list-1/make_pi.py new file mode 100644 index 0000000..506e352 --- /dev/null +++ b/list-1/make_pi.py @@ -0,0 +1,7 @@ +def make_pi(): + """ + Return an int array length 3 containing the first 3 digits of pi, {3, 1, 4}. + """ + pass + +print(make_pi()) \ No newline at end of file diff --git a/list-1/max_end3.py b/list-1/max_end3.py new file mode 100644 index 0000000..202139d --- /dev/null +++ b/list-1/max_end3.py @@ -0,0 +1,9 @@ +def max_end3(nums): + """ + Given an array of ints length 3, figure out which is larger, the first or last element in the array, and set all the other elements to be that value. Return the changed array. + """ + pass + +print(max_end3([1, 2, 3])) +print(max_end3([11, 5, 9])) +print(max_end3([2, 11, 3])) \ No newline at end of file diff --git a/list-1/middle_way.py b/list-1/middle_way.py new file mode 100644 index 0000000..8f4f03f --- /dev/null +++ b/list-1/middle_way.py @@ -0,0 +1,9 @@ +def middle_way(a, b): + """ + Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements. + """ + pass + +print(middle_way([1, 2, 3], [4, 5, 6])) +print(middle_way([7, 7, 7], [3, 8, 0])) +print(middle_way([5, 2, 9], [1, 4, 5])) \ No newline at end of file diff --git a/list-1/reverse3.py b/list-1/reverse3.py new file mode 100644 index 0000000..23020ab --- /dev/null +++ b/list-1/reverse3.py @@ -0,0 +1,9 @@ +def reverse3(nums): + """ + Given an array of ints length 3, return a new array with the elements in reverse order, so {1, 2, 3} becomes {3, 2, 1}. + """ + pass + +print(reverse3([1, 2, 3])) +print(reverse3([5, 11, 9])) +print(reverse3([7, 0, 0])) \ No newline at end of file diff --git a/list-1/rotate_left3.py b/list-1/rotate_left3.py new file mode 100644 index 0000000..1c8d58c --- /dev/null +++ b/list-1/rotate_left3.py @@ -0,0 +1,9 @@ +def rotate_left3(nums): + """ + Given an array of ints length 3, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}. + """ + pass + +print(rotate_left3([1, 2, 3])) +print(rotate_left3([5, 11, 9])) +print(rotate_left3([7, 0, 0])) \ No newline at end of file diff --git a/list-1/same_first_last.py b/list-1/same_first_last.py new file mode 100644 index 0000000..111a7ba --- /dev/null +++ b/list-1/same_first_last.py @@ -0,0 +1,9 @@ +def same_first_last(nums): + """ + Given an array of ints, return True if the array is length 1 or more, and the first element and the last element are equal. + """ + pass + +print(same_first_last([1, 2, 3])) +print(same_first_last([1, 2, 3, 1])) +print(same_first_last([1, 2, 1])) \ No newline at end of file diff --git a/list-1/sum2.py b/list-1/sum2.py new file mode 100644 index 0000000..5b169d8 --- /dev/null +++ b/list-1/sum2.py @@ -0,0 +1,9 @@ +def sum2(nums): + """ + Given an array of ints, return the sum of the first 2 elements in the array. If the array length is less than 2, just sum up the elements that exist, returning 0 if the array is length 0. + """ + pass + +print(sum2([1, 2, 3])) +print(sum2([1, 1])) +print(sum2([1, 1, 1, 1])) \ No newline at end of file diff --git a/list-1/sum3.py b/list-1/sum3.py new file mode 100644 index 0000000..0a0a156 --- /dev/null +++ b/list-1/sum3.py @@ -0,0 +1,9 @@ +def sum3(nums): + """ + Given an array of ints length 3, return the sum of all the elements. + """ + pass + +print(sum3([1, 2, 3])) +print(sum3([5, 11, 2])) +print(sum3([7, 0, 0])) \ No newline at end of file diff --git a/list-2/big_diff.py b/list-2/big_diff.py new file mode 100644 index 0000000..62d6993 --- /dev/null +++ b/list-2/big_diff.py @@ -0,0 +1,9 @@ +def big_diff(nums): + """ + Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. Note: the built-in min(v1, v2) and max(v1, v2) functions return the smaller or larger of two values. + """ + pass + +print(big_diff([10, 3, 5, 6])) +print(big_diff([7, 2, 10, 9])) +print(big_diff([2, 10, 7, 2])) \ No newline at end of file diff --git a/list-2/centered_average.py b/list-2/centered_average.py new file mode 100644 index 0000000..fab9955 --- /dev/null +++ b/list-2/centered_average.py @@ -0,0 +1,9 @@ +def centered_average(nums): + """ + Return the "centered" average of an array of ints, which we'll say is the mean average of the values, except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use int division to produce the final average. You may assume that the array is length 3 or more. + """ + pass + +print(centered_average([1, 2, 3, 4, 100])) +print(centered_average([1, 1, 5, 5, 10, 8, 7])) +print(centered_average([-10, -4, -2, -4, -2, 0])) \ No newline at end of file diff --git a/list-2/has22.py b/list-2/has22.py new file mode 100644 index 0000000..777d40f --- /dev/null +++ b/list-2/has22.py @@ -0,0 +1,9 @@ +def has22(nums): + """ + Given an array of ints, return True if the array contains a 2 next to a 2 somewhere. + """ + pass + +print(has22([1, 2, 2])) +print(has22([1, 2, 1, 2])) +print(has22([2, 1, 2])) \ No newline at end of file diff --git a/list-2/sum13.py b/list-2/sum13.py new file mode 100644 index 0000000..579d8cd --- /dev/null +++ b/list-2/sum13.py @@ -0,0 +1,9 @@ +def sum13(nums): + """ + Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count. + """ + pass + +print(sum13([1, 2, 2, 1])) +print(sum13([1, 1])) +print(sum13([1, 2, 2, 1, 13])) \ No newline at end of file diff --git a/list-2/sum67.py b/list-2/sum67.py new file mode 100644 index 0000000..ac11498 --- /dev/null +++ b/list-2/sum67.py @@ -0,0 +1,9 @@ +def sum67(nums): + """ + Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers. + """ + pass + +print(sum67([1, 2, 2])) +print(sum67([1, 2, 2, 6, 99, 99, 7])) +print(sum67([1, 1, 6, 7, 2])) \ No newline at end of file diff --git a/logic-1/alarm_clock.py b/logic-1/alarm_clock.py new file mode 100644 index 0000000..1e49966 --- /dev/null +++ b/logic-1/alarm_clock.py @@ -0,0 +1,9 @@ +def alarm_clock(day, vacation): + """ + Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off". + """ + pass + +print(alarm_clock(1, False)) +print(alarm_clock(5, False)) +print(alarm_clock(0, False)) \ No newline at end of file diff --git a/logic-1/caught_speeding.py b/logic-1/caught_speeding.py new file mode 100644 index 0000000..ecd64eb --- /dev/null +++ b/logic-1/caught_speeding.py @@ -0,0 +1,9 @@ +def caught_speeding(speed, is_birthday): + """ + You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases. + """ + pass + +print(caught_speeding(60, False)) +print(caught_speeding(65, False)) +print(caught_speeding(65, True)) \ No newline at end of file diff --git a/logic-1/date_fashion.py b/logic-1/date_fashion.py new file mode 100644 index 0000000..e70f70b --- /dev/null +++ b/logic-1/date_fashion.py @@ -0,0 +1,9 @@ +def date_fashion(you, date): + """ + You and your date are trying to get a table at a restaurant. The parameter "you" is the stylishness of your clothes, in the range 0..10, and "date" is the stylishness of your date's clothes. The result getting the table is encoded as an int value with 0=no, 1=maybe, 2=yes. If either of you is very stylish, 8 or more, then the result is 2 (yes). With the exception that if either of you has style of 2 or less, then the result is 0 (no). Otherwise the result is 1 (maybe). + """ + pass + +print(date_fashion(5, 10)) +print(date_fashion(5, 2)) +print(date_fashion(5, 5)) \ No newline at end of file diff --git a/logic-1/in1to10.py b/logic-1/in1to10.py new file mode 100644 index 0000000..361eff8 --- /dev/null +++ b/logic-1/in1to10.py @@ -0,0 +1,9 @@ +def in1to10(n, outside_mode): + """ + Given a number n, return True if n is in the range 1..10, inclusive. Unless outside_mode is True, in which case return True if the number is less or equal to 1, or greater or equal to 10. + """ + pass + +print(in1to10(5, False)) +print(in1to10(11, False)) +print(in1to10(11, True)) \ No newline at end of file diff --git a/logic-1/love6.py b/logic-1/love6.py new file mode 100644 index 0000000..982af84 --- /dev/null +++ b/logic-1/love6.py @@ -0,0 +1,9 @@ +def love6(a, b): + """ + The number 6 is a truly great number. Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6. Note: the function abs(num) computes the absolute value of a number. + """ + pass + +print(love6(6, 4)) +print(love6(4, 5)) +print(love6(1, 5)) \ No newline at end of file diff --git a/logic-1/near_ten.py b/logic-1/near_ten.py new file mode 100644 index 0000000..b5f081a --- /dev/null +++ b/logic-1/near_ten.py @@ -0,0 +1,9 @@ +def near_ten(num): + """ + Given a non-negative number "num", return True if num is within 2 of a multiple of 10. Note: (a % b) is the remainder of dividing a by b, so (7 % 5) is 2. See also: Introduction to Mod + """ + pass + +print(near_ten(12)) +print(near_ten(17)) +print(near_ten(19)) \ No newline at end of file diff --git a/logic-1/sorta_sum.py b/logic-1/sorta_sum.py new file mode 100644 index 0000000..ba1e89a --- /dev/null +++ b/logic-1/sorta_sum.py @@ -0,0 +1,9 @@ +def sorta_sum(a, b): + """ + Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20. + """ + pass + +print(sorta_sum(3, 4)) +print(sorta_sum(9, 4)) +print(sorta_sum(10, 11)) \ No newline at end of file diff --git a/logic-1/squirrel_play.py b/logic-1/squirrel_play.py new file mode 100644 index 0000000..99b3ff7 --- /dev/null +++ b/logic-1/squirrel_play.py @@ -0,0 +1,9 @@ +def squirrel_play(temp, is_summer): + """ + The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a boolean is_summer, return True if the squirrels play and False otherwise. + """ + pass + +print(squirrel_play(70, False)) +print(squirrel_play(95, False)) +print(squirrel_play(95, True)) \ No newline at end of file diff --git a/logic-2/close_far.py b/logic-2/close_far.py new file mode 100644 index 0000000..859b1b2 --- /dev/null +++ b/logic-2/close_far.py @@ -0,0 +1,9 @@ +def close_far(a, b, c): + """ + Given three ints, a b c, return True if one of b or c is "close" (differing from a by at most 1), while the other is "far", differing from both other values by 2 or more. Note: abs(num) computes the absolute value of a number. + """ + pass + +print(close_far(1, 2, 10)) +print(close_far(1, 2, 3)) +print(close_far(4, 1, 3)) \ No newline at end of file diff --git a/logic-2/lucky_sum.py b/logic-2/lucky_sum.py new file mode 100644 index 0000000..8e759ae --- /dev/null +++ b/logic-2/lucky_sum.py @@ -0,0 +1,9 @@ +def lucky_sum(a, b, c): + """ + Given 3 int values, a b c, return their sum. However, if one of the values is 13 then it does not count towards the sum and values to its right do not count. So for example, if b is 13, then both b and c do not count. + """ + pass + +print(lucky_sum(1, 2, 3)) +print(lucky_sum(1, 2, 13)) +print(lucky_sum(1, 13, 3)) \ No newline at end of file diff --git a/logic-2/make_bricks.py b/logic-2/make_bricks.py new file mode 100644 index 0000000..cfb1cdc --- /dev/null +++ b/logic-2/make_bricks.py @@ -0,0 +1,9 @@ +def make_bricks(small, big, goal): + """ + We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks. This is a little harder than it looks and can be done without any loops. See also: Introduction to MakeBricks + """ + pass + +print(make_bricks(3, 1, 8)) +print(make_bricks(3, 1, 9)) +print(make_bricks(3, 2, 10)) \ No newline at end of file diff --git a/logic-2/make_chocolate.py b/logic-2/make_chocolate.py new file mode 100644 index 0000000..e6afa0d --- /dev/null +++ b/logic-2/make_chocolate.py @@ -0,0 +1,9 @@ +def make_chocolate(small, big, goal): + """ + We want make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Return the number of small bars to use, assuming we always use big bars before small bars. Return -1 if it can't be done. + """ + pass + +print(make_chocolate(4, 1, 9)) +print(make_chocolate(4, 1, 10)) +print(make_chocolate(4, 1, 7)) \ No newline at end of file diff --git a/logic-2/no_teen_sum.py b/logic-2/no_teen_sum.py new file mode 100644 index 0000000..b2c22d6 --- /dev/null +++ b/logic-2/no_teen_sum.py @@ -0,0 +1,9 @@ +def no_teen_sum(a, b, c): + """ + Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "def fix_teen(n):"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main no_teen_sum(). + """ + pass + +print(no_teen_sum(1, 2, 3)) +print(no_teen_sum(2, 13, 1)) +print(no_teen_sum(2, 1, 14)) \ No newline at end of file diff --git a/logic-2/round_sum.py b/logic-2/round_sum.py new file mode 100644 index 0000000..908d69e --- /dev/null +++ b/logic-2/round_sum.py @@ -0,0 +1,9 @@ +def round_sum(a, b, c): + """ + For this problem, we'll round an int value up to the next multiple of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20. Alternately, round down to the previous multiple of 10 if its rightmost digit is less than 5, so 12 rounds down to 10. Given 3 ints, a b c, return the sum of their rounded values. To avoid code repetition, write a separate helper "def round10(num):" and call it 3 times. Write the helper entirely below and at the same indent level as round_sum(). + """ + pass + +print(round_sum(16, 17, 18)) +print(round_sum(12, 13, 14)) +print(round_sum(6, 4, 4)) \ No newline at end of file diff --git a/string-1/combo_string.py b/string-1/combo_string.py new file mode 100644 index 0000000..98830ae --- /dev/null +++ b/string-1/combo_string.py @@ -0,0 +1,9 @@ +def combo_string(a, b): + """ + Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0). + """ + pass + +print(combo_string('Hello', 'hi')) +print(combo_string('hi', 'Hello')) +print(combo_string('aaa', 'b')) \ No newline at end of file diff --git a/string-1/extra_end.py b/string-1/extra_end.py new file mode 100644 index 0000000..8b6d5e2 --- /dev/null +++ b/string-1/extra_end.py @@ -0,0 +1,9 @@ +def extra_end(str): + """ + Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2. + """ + pass + +print(extra_end('Hello')) +print(extra_end('ab')) +print(extra_end('Hi')) \ No newline at end of file diff --git a/string-1/first_half.py b/string-1/first_half.py new file mode 100644 index 0000000..3059880 --- /dev/null +++ b/string-1/first_half.py @@ -0,0 +1,9 @@ +def first_half(str): + """ + Given a string of even length, return the first half. So the string "WooHoo" yields "Woo". + """ + pass + +print(first_half('WooHoo')) +print(first_half('HelloThere')) +print(first_half('abcdef')) \ No newline at end of file diff --git a/string-1/first_two.py b/string-1/first_two.py new file mode 100644 index 0000000..e1c4c40 --- /dev/null +++ b/string-1/first_two.py @@ -0,0 +1,9 @@ +def first_two(str): + """ + Given a string, return the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there is, so "X" yields "X", and the empty string "" yields the empty string "". + """ + pass + +print(first_two('Hello')) +print(first_two('abcdefg')) +print(first_two('ab')) \ No newline at end of file diff --git a/string-1/left2.py b/string-1/left2.py new file mode 100644 index 0000000..801ccb5 --- /dev/null +++ b/string-1/left2.py @@ -0,0 +1,9 @@ +def left2(str): + """ + Given a string, return a "rotated left 2" version where the first 2 chars are moved to the end. The string length will be at least 2. + """ + pass + +print(left2('Hello')) +print(left2('java')) +print(left2('Hi')) \ No newline at end of file diff --git a/string-1/make_abba.py b/string-1/make_abba.py new file mode 100644 index 0000000..dc82f47 --- /dev/null +++ b/string-1/make_abba.py @@ -0,0 +1,9 @@ +def make_abba(a, b): + """ + Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi". + """ + pass + +print(make_abba('Hi', 'Bye')) +print(make_abba('Yo', 'Alice')) +print(make_abba('What', 'Up')) \ No newline at end of file diff --git a/string-1/make_out_word.py b/string-1/make_out_word.py new file mode 100644 index 0000000..3c13cad --- /dev/null +++ b/string-1/make_out_word.py @@ -0,0 +1,9 @@ +def make_out_word(out, word): + """ + Given an "out" string length 4, such as "<<>>", and a word, return a new string where the word is in the middle of the out string, e.g. "<>". + """ + pass + +print(make_out_word('<<>>', 'Yay')) +print(make_out_word('<<>>', 'WooHoo')) +print(make_out_word('[[]]', 'word')) \ No newline at end of file diff --git a/string-1/make_tags.py b/string-1/make_tags.py new file mode 100644 index 0000000..52949d7 --- /dev/null +++ b/string-1/make_tags.py @@ -0,0 +1,9 @@ +def make_tags(tag, word): + """ + The web is built with HTML strings like "Yay" which draws Yay as italic text. In this example, the "i" tag makes and which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "Yay". + """ + pass + +print(make_tags('i', 'Yay')) +print(make_tags('i', 'Hello')) +print(make_tags('cite', 'Yay')) \ No newline at end of file diff --git a/string-1/non_start.py b/string-1/non_start.py new file mode 100644 index 0000000..badb7b3 --- /dev/null +++ b/string-1/non_start.py @@ -0,0 +1,9 @@ +def non_start(a, b): + """ + Given 2 strings, return their concatenation, except omit the first char of each. The strings will be at least length 1. + """ + pass + +print(non_start('Hello', 'There')) +print(non_start('java', 'code')) +print(non_start('shotl', 'java')) \ No newline at end of file diff --git a/string-1/without_end.py b/string-1/without_end.py new file mode 100644 index 0000000..9fe8072 --- /dev/null +++ b/string-1/without_end.py @@ -0,0 +1,9 @@ +def without_end(str): + """ + Given a string, return a version without the first and last char, so "Hello" yields "ell". The string length will be at least 2. + """ + pass + +print(without_end('Hello')) +print(without_end('java')) +print(without_end('coding')) \ No newline at end of file diff --git a/string-2/cat_dog.py b/string-2/cat_dog.py new file mode 100644 index 0000000..b619ab4 --- /dev/null +++ b/string-2/cat_dog.py @@ -0,0 +1,9 @@ +def cat_dog(str): + """ + Return True if the string "cat" and "dog" appear the same number of times in the given string. + """ + pass + +print(cat_dog('catdog')) +print(cat_dog('catcat')) +print(cat_dog('1cat1cadodog')) \ No newline at end of file diff --git a/string-2/count_code.py b/string-2/count_code.py new file mode 100644 index 0000000..4f14ba7 --- /dev/null +++ b/string-2/count_code.py @@ -0,0 +1,9 @@ +def count_code(str): + """ + Return the number of times that the string "code" appears anywhere in the given string, except we'll accept any letter for the 'd', so "cope" and "cooe" count. + """ + pass + +print(count_code('aaacodebbb')) +print(count_code('codexxcode')) +print(count_code('cozexxcope')) \ No newline at end of file diff --git a/string-2/count_hi.py b/string-2/count_hi.py new file mode 100644 index 0000000..38803b4 --- /dev/null +++ b/string-2/count_hi.py @@ -0,0 +1,9 @@ +def count_hi(str): + """ + Return the number of times that the string "hi" appears anywhere in the given string. + """ + pass + +print(count_hi('abc hi ho')) +print(count_hi('ABChi hi')) +print(count_hi('hihi')) \ No newline at end of file diff --git a/string-2/end_other.py b/string-2/end_other.py new file mode 100644 index 0000000..12ed685 --- /dev/null +++ b/string-2/end_other.py @@ -0,0 +1,9 @@ +def end_other(a, b): + """ + Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: s.lower() returns the lowercase version of a string. + """ + pass + +print(end_other('Hiabc', 'abc')) +print(end_other('AbC', 'HiaBc')) +print(end_other('abc', 'abXabc')) \ No newline at end of file diff --git a/string-2/xyz_there.py b/string-2/xyz_there.py new file mode 100644 index 0000000..b78dd9f --- /dev/null +++ b/string-2/xyz_there.py @@ -0,0 +1,9 @@ +def xyz_there(str): + """ + Return True if the given string contains an appearance of "xyz" where the xyz is not directly preceeded by a period (.). So "xxyz" counts but "x.xyz" does not. + """ + pass + +print(xyz_there('abcxyz')) +print(xyz_there('abc.xyz')) +print(xyz_there('xyz.abc')) \ No newline at end of file diff --git a/warmup-1/diff21.py b/warmup-1/diff21.py new file mode 100644 index 0000000..38c98fd --- /dev/null +++ b/warmup-1/diff21.py @@ -0,0 +1,9 @@ +def diff21(n): + """ + Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21. + """ + pass + +print(diff21(19)) +print(diff21(10)) +print(diff21(21)) \ No newline at end of file diff --git a/warmup-1/front3.py b/warmup-1/front3.py new file mode 100644 index 0000000..03c3e61 --- /dev/null +++ b/warmup-1/front3.py @@ -0,0 +1,9 @@ +def front3(str): + """ + Given a string, we'll say that the front is the first 3 chars of the string. If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front. + """ + pass + +print(front3('Java')) +print(front3('Chocolate')) +print(front3('abc')) \ No newline at end of file diff --git a/warmup-1/front_back.py b/warmup-1/front_back.py new file mode 100644 index 0000000..109bc73 --- /dev/null +++ b/warmup-1/front_back.py @@ -0,0 +1,9 @@ +def front_back(str): + """ + Given a string, return a new string where the first and last chars have been exchanged. + """ + pass + +print(front_back('code')) +print(front_back('a')) +print(front_back('ab')) \ No newline at end of file diff --git a/warmup-1/makes10.py b/warmup-1/makes10.py new file mode 100644 index 0000000..e24ae98 --- /dev/null +++ b/warmup-1/makes10.py @@ -0,0 +1,9 @@ +def makes10(a, b): + """ + Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10. + """ + pass + +print(makes10(9, 10)) +print(makes10(9, 9)) +print(makes10(1, 9)) \ No newline at end of file diff --git a/warmup-1/missing_char.py b/warmup-1/missing_char.py new file mode 100644 index 0000000..bfc9966 --- /dev/null +++ b/warmup-1/missing_char.py @@ -0,0 +1,9 @@ +def missing_char(str, n): + """ + Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..len(str)-1 inclusive). + """ + pass + +print(missing_char('kitten', 1)) +print(missing_char('kitten', 0)) +print(missing_char('kitten', 4)) \ No newline at end of file diff --git a/warmup-1/monkey_trouble.py b/warmup-1/monkey_trouble.py new file mode 100644 index 0000000..3c54c55 --- /dev/null +++ b/warmup-1/monkey_trouble.py @@ -0,0 +1,9 @@ +def monkey_trouble(a_smile, b_smile): + """ + We have two monkeys, a and b, and the parameters a_smile and b_smile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return True if we are in trouble. + """ + pass + +print(monkey_trouble(True, True)) +print(monkey_trouble(False, False)) +print(monkey_trouble(True, False)) \ No newline at end of file diff --git a/warmup-1/near_hundred.py b/warmup-1/near_hundred.py new file mode 100644 index 0000000..4bc7daf --- /dev/null +++ b/warmup-1/near_hundred.py @@ -0,0 +1,9 @@ +def near_hundred(n): + """ + Given an int n, return True if it is within 10 of 100 or 200. Note: abs(num) computes the absolute value of a number. + """ + pass + +print(near_hundred(93)) +print(near_hundred(90)) +print(near_hundred(89)) \ No newline at end of file diff --git a/warmup-1/not_string.py b/warmup-1/not_string.py new file mode 100644 index 0000000..466304b --- /dev/null +++ b/warmup-1/not_string.py @@ -0,0 +1,9 @@ +def not_string(str): + """ + Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. + """ + pass + +print(not_string('candy')) +print(not_string('x')) +print(not_string('not bad')) \ No newline at end of file diff --git a/warmup-1/parrot_trouble.py b/warmup-1/parrot_trouble.py new file mode 100644 index 0000000..a4db2a8 --- /dev/null +++ b/warmup-1/parrot_trouble.py @@ -0,0 +1,9 @@ +def parrot_trouble(talking, hour): + """ + We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return True if we are in trouble. + """ + pass + +print(parrot_trouble(True, 6)) +print(parrot_trouble(True, 7)) +print(parrot_trouble(False, 6)) \ No newline at end of file diff --git a/warmup-1/pos_neg.py b/warmup-1/pos_neg.py new file mode 100644 index 0000000..571d45c --- /dev/null +++ b/warmup-1/pos_neg.py @@ -0,0 +1,9 @@ +def pos_neg(a, b, negative): + """ + Given 2 int values, return True if one is negative and one is positive. Except if the parameter "negative" is True, then return True only if both are negative. + """ + pass + +print(pos_neg(1, -1, False)) +print(pos_neg(-1, 1, False)) +print(pos_neg(-4, -5, True)) \ No newline at end of file diff --git a/warmup-1/sum_double.py b/warmup-1/sum_double.py new file mode 100644 index 0000000..c3e8892 --- /dev/null +++ b/warmup-1/sum_double.py @@ -0,0 +1,9 @@ +def sum_double(a, b): + """ + Given two int values, return their sum. Unless the two values are the same, then return double their sum. + """ + pass + +print(sum_double(1, 2)) +print(sum_double(3, 2)) +print(sum_double(2, 2)) \ No newline at end of file diff --git a/warmup-2/array123.py b/warmup-2/array123.py new file mode 100644 index 0000000..7271fdf --- /dev/null +++ b/warmup-2/array123.py @@ -0,0 +1,9 @@ +def array123(nums): + """ + Given an array of ints, return True if the sequence of numbers 1, 2, 3 appears in the array somewhere. + """ + pass + +print(array123([1, 1, 2, 3, 1])) +print(array123([1, 1, 2, 4, 1])) +print(array123([1, 1, 2, 1, 2, 3])) \ No newline at end of file diff --git a/warmup-2/array_count9.py b/warmup-2/array_count9.py new file mode 100644 index 0000000..9d0b975 --- /dev/null +++ b/warmup-2/array_count9.py @@ -0,0 +1,9 @@ +def array_count9(nums): + """ + Given an array of ints, return the number of 9's in the array. + """ + pass + +print(array_count9([1, 2, 9])) +print(array_count9([1, 9, 9])) +print(array_count9([1, 9, 9, 3, 9])) \ No newline at end of file diff --git a/warmup-2/array_front9.py b/warmup-2/array_front9.py new file mode 100644 index 0000000..228f087 --- /dev/null +++ b/warmup-2/array_front9.py @@ -0,0 +1,9 @@ +def array_front9(nums): + """ + Given an array of ints, return True if one of the first 4 elements in the array is a 9. The array length may be less than 4. + """ + pass + +print(array_front9([1, 2, 9, 3, 4])) +print(array_front9([1, 2, 3, 4, 9])) +print(array_front9([1, 2, 3, 4, 5])) \ No newline at end of file diff --git a/warmup-2/front_times.py b/warmup-2/front_times.py new file mode 100644 index 0000000..767b765 --- /dev/null +++ b/warmup-2/front_times.py @@ -0,0 +1,9 @@ +def front_times(str, n): + """ + Given a string and a non-negative int n, we'll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front; + """ + pass + +print(front_times('Chocolate', 2)) +print(front_times('Chocolate', 3)) +print(front_times('Abc', 3)) \ No newline at end of file diff --git a/warmup-2/last2.py b/warmup-2/last2.py new file mode 100644 index 0000000..5c3ea24 --- /dev/null +++ b/warmup-2/last2.py @@ -0,0 +1,9 @@ +def last2(str): + """ + Given a string, return the count of the number of times that a substring length 2 appears in the string and also as the last 2 chars of the string, so "hixxxhi" yields 1 (we won't count the end substring). + """ + pass + +print(last2('hixxhi')) +print(last2('xaxxaxaxx')) +print(last2('axxxaaxx')) \ No newline at end of file diff --git a/warmup-2/string_bits.py b/warmup-2/string_bits.py new file mode 100644 index 0000000..0588eef --- /dev/null +++ b/warmup-2/string_bits.py @@ -0,0 +1,9 @@ +def string_bits(str): + """ + Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo". + """ + pass + +print(string_bits('Hello')) +print(string_bits('Hi')) +print(string_bits('Heeololeo')) \ No newline at end of file diff --git a/warmup-2/string_match.py b/warmup-2/string_match.py new file mode 100644 index 0000000..95d6f26 --- /dev/null +++ b/warmup-2/string_match.py @@ -0,0 +1,9 @@ +def string_match(a, b): + """ + Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. + """ + pass + +print(string_match('xxcaazz', 'xxbaaz')) +print(string_match('abc', 'abc')) +print(string_match('abc', 'axc')) \ No newline at end of file diff --git a/warmup-2/string_splosion.py b/warmup-2/string_splosion.py new file mode 100644 index 0000000..7843ce5 --- /dev/null +++ b/warmup-2/string_splosion.py @@ -0,0 +1,9 @@ +def string_splosion(str): + """ + Given a non-empty string like "Code" return a string like "CCoCodCode". + """ + pass + +print(string_splosion('Code')) +print(string_splosion('abc')) +print(string_splosion('ab')) \ No newline at end of file From 34972775b28ca138dd8acd085dbdd702546bde17 Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Sun, 7 Oct 2018 22:14:55 -0400 Subject: [PATCH 2/7] Fixed formatting --- codingbat_exercise_scraper.py | 18 +++++++++--------- list-1/common_end.py | 2 +- list-1/has23.py | 2 +- list-1/make_ends.py | 2 +- list-1/make_pi.py | 2 +- list-1/max_end3.py | 2 +- list-1/middle_way.py | 2 +- list-1/reverse3.py | 2 +- list-1/rotate_left3.py | 2 +- list-1/same_first_last.py | 2 +- list-1/sum2.py | 2 +- list-1/sum3.py | 2 +- list-2/big_diff.py | 2 +- list-2/centered_average.py | 2 +- list-2/has22.py | 2 +- list-2/sum13.py | 2 +- list-2/sum67.py | 2 +- logic-1/alarm_clock.py | 2 +- logic-1/caught_speeding.py | 2 +- logic-1/date_fashion.py | 2 +- logic-1/in1to10.py | 2 +- logic-1/love6.py | 2 +- logic-1/near_ten.py | 2 +- logic-1/sorta_sum.py | 2 +- logic-1/squirrel_play.py | 2 +- logic-2/close_far.py | 2 +- logic-2/lucky_sum.py | 2 +- logic-2/make_bricks.py | 2 +- logic-2/make_chocolate.py | 2 +- logic-2/no_teen_sum.py | 2 +- logic-2/round_sum.py | 2 +- string-1/combo_string.py | 2 +- string-1/extra_end.py | 2 +- string-1/first_half.py | 2 +- string-1/first_two.py | 2 +- string-1/left2.py | 2 +- string-1/make_abba.py | 2 +- string-1/make_out_word.py | 2 +- string-1/make_tags.py | 2 +- string-1/non_start.py | 2 +- string-1/without_end.py | 2 +- string-2/cat_dog.py | 2 +- string-2/count_code.py | 2 +- string-2/count_hi.py | 2 +- string-2/end_other.py | 2 +- string-2/xyz_there.py | 2 +- warmup-1/diff21.py | 2 +- warmup-1/front3.py | 2 +- warmup-1/front_back.py | 2 +- warmup-1/makes10.py | 2 +- warmup-1/missing_char.py | 2 +- warmup-1/monkey_trouble.py | 2 +- warmup-1/near_hundred.py | 2 +- warmup-1/not_string.py | 2 +- warmup-1/parrot_trouble.py | 2 +- warmup-1/pos_neg.py | 2 +- warmup-1/sum_double.py | 2 +- warmup-2/array123.py | 2 +- warmup-2/array_count9.py | 2 +- warmup-2/array_front9.py | 2 +- warmup-2/front_times.py | 2 +- warmup-2/last2.py | 2 +- warmup-2/string_bits.py | 2 +- warmup-2/string_match.py | 2 +- warmup-2/string_splosion.py | 2 +- 65 files changed, 73 insertions(+), 73 deletions(-) diff --git a/codingbat_exercise_scraper.py b/codingbat_exercise_scraper.py index 8eef860..bebd358 100644 --- a/codingbat_exercise_scraper.py +++ b/codingbat_exercise_scraper.py @@ -4,7 +4,6 @@ Author: Ha Min Ko """ - import requests, bs4 import os from os.path import exists @@ -46,28 +45,29 @@ if (exists(title)): print(title, 'exists already.') else: - functiondefiner = html2.select('div[id=ace_div]')[0].text.strip() - functiondescription = html2.select('p[class=max2]')[0].text.strip() - functiontest = [] + function_definer = html2.select('div[id=ace_div]')[0].text.strip() + function_description = html2.select('p[class=max2]')[0].text.strip() + function_test = [] for br in html2.find_all('br'): following = br.nextSibling if name1 in following: - functiontest.append(following) + function_test.append(following) # Create a file that can be written to. print('Creating file', title, 'in folder', name ) outputfile = open(title, 'w') # Write data to the file: - outputfile.write(functiondefiner) + outputfile.write(function_definer) outputfile.write('\n\t"""') - outputfile.write('\n\t' + functiondescription) + outputfile.write('\n\t' + function_description) outputfile.write('\n\t"""') outputfile.write('\n\tpass') outputfile.write('\n') - for test in functiontest: + for test in function_test: test = test.split('→')[0].strip() outputfile.write('\nprint(' + test + ')') + outputfile.write('\n') # Close the file after writing to it - outputfile.close() \ No newline at end of file + outputfile.close() diff --git a/list-1/common_end.py b/list-1/common_end.py index 95a3069..a74182e 100644 --- a/list-1/common_end.py +++ b/list-1/common_end.py @@ -6,4 +6,4 @@ def common_end(a, b): print(common_end([1, 2, 3], [7, 3])) print(common_end([1, 2, 3], [7, 3, 2])) -print(common_end([1, 2, 3], [1, 3])) \ No newline at end of file +print(common_end([1, 2, 3], [1, 3])) diff --git a/list-1/has23.py b/list-1/has23.py index 8584ac4..10231dd 100644 --- a/list-1/has23.py +++ b/list-1/has23.py @@ -6,4 +6,4 @@ def has23(nums): print(has23([2, 5])) print(has23([4, 3])) -print(has23([4, 5])) \ No newline at end of file +print(has23([4, 5])) diff --git a/list-1/make_ends.py b/list-1/make_ends.py index 9700981..0d45378 100644 --- a/list-1/make_ends.py +++ b/list-1/make_ends.py @@ -6,4 +6,4 @@ def make_ends(nums): print(make_ends([1, 2, 3])) print(make_ends([1, 2, 3, 4])) -print(make_ends([7, 4, 6, 2])) \ No newline at end of file +print(make_ends([7, 4, 6, 2])) diff --git a/list-1/make_pi.py b/list-1/make_pi.py index 506e352..2af7e09 100644 --- a/list-1/make_pi.py +++ b/list-1/make_pi.py @@ -4,4 +4,4 @@ def make_pi(): """ pass -print(make_pi()) \ No newline at end of file +print(make_pi()) diff --git a/list-1/max_end3.py b/list-1/max_end3.py index 202139d..5cbf830 100644 --- a/list-1/max_end3.py +++ b/list-1/max_end3.py @@ -6,4 +6,4 @@ def max_end3(nums): print(max_end3([1, 2, 3])) print(max_end3([11, 5, 9])) -print(max_end3([2, 11, 3])) \ No newline at end of file +print(max_end3([2, 11, 3])) diff --git a/list-1/middle_way.py b/list-1/middle_way.py index 8f4f03f..73eb5f6 100644 --- a/list-1/middle_way.py +++ b/list-1/middle_way.py @@ -6,4 +6,4 @@ def middle_way(a, b): print(middle_way([1, 2, 3], [4, 5, 6])) print(middle_way([7, 7, 7], [3, 8, 0])) -print(middle_way([5, 2, 9], [1, 4, 5])) \ No newline at end of file +print(middle_way([5, 2, 9], [1, 4, 5])) diff --git a/list-1/reverse3.py b/list-1/reverse3.py index 23020ab..eb83b54 100644 --- a/list-1/reverse3.py +++ b/list-1/reverse3.py @@ -6,4 +6,4 @@ def reverse3(nums): print(reverse3([1, 2, 3])) print(reverse3([5, 11, 9])) -print(reverse3([7, 0, 0])) \ No newline at end of file +print(reverse3([7, 0, 0])) diff --git a/list-1/rotate_left3.py b/list-1/rotate_left3.py index 1c8d58c..4563da9 100644 --- a/list-1/rotate_left3.py +++ b/list-1/rotate_left3.py @@ -6,4 +6,4 @@ def rotate_left3(nums): print(rotate_left3([1, 2, 3])) print(rotate_left3([5, 11, 9])) -print(rotate_left3([7, 0, 0])) \ No newline at end of file +print(rotate_left3([7, 0, 0])) diff --git a/list-1/same_first_last.py b/list-1/same_first_last.py index 111a7ba..1e3717c 100644 --- a/list-1/same_first_last.py +++ b/list-1/same_first_last.py @@ -6,4 +6,4 @@ def same_first_last(nums): print(same_first_last([1, 2, 3])) print(same_first_last([1, 2, 3, 1])) -print(same_first_last([1, 2, 1])) \ No newline at end of file +print(same_first_last([1, 2, 1])) diff --git a/list-1/sum2.py b/list-1/sum2.py index 5b169d8..df30702 100644 --- a/list-1/sum2.py +++ b/list-1/sum2.py @@ -6,4 +6,4 @@ def sum2(nums): print(sum2([1, 2, 3])) print(sum2([1, 1])) -print(sum2([1, 1, 1, 1])) \ No newline at end of file +print(sum2([1, 1, 1, 1])) diff --git a/list-1/sum3.py b/list-1/sum3.py index 0a0a156..a98c246 100644 --- a/list-1/sum3.py +++ b/list-1/sum3.py @@ -6,4 +6,4 @@ def sum3(nums): print(sum3([1, 2, 3])) print(sum3([5, 11, 2])) -print(sum3([7, 0, 0])) \ No newline at end of file +print(sum3([7, 0, 0])) diff --git a/list-2/big_diff.py b/list-2/big_diff.py index 62d6993..34b4e33 100644 --- a/list-2/big_diff.py +++ b/list-2/big_diff.py @@ -6,4 +6,4 @@ def big_diff(nums): print(big_diff([10, 3, 5, 6])) print(big_diff([7, 2, 10, 9])) -print(big_diff([2, 10, 7, 2])) \ No newline at end of file +print(big_diff([2, 10, 7, 2])) diff --git a/list-2/centered_average.py b/list-2/centered_average.py index fab9955..79df72e 100644 --- a/list-2/centered_average.py +++ b/list-2/centered_average.py @@ -6,4 +6,4 @@ def centered_average(nums): print(centered_average([1, 2, 3, 4, 100])) print(centered_average([1, 1, 5, 5, 10, 8, 7])) -print(centered_average([-10, -4, -2, -4, -2, 0])) \ No newline at end of file +print(centered_average([-10, -4, -2, -4, -2, 0])) diff --git a/list-2/has22.py b/list-2/has22.py index 777d40f..7e932d0 100644 --- a/list-2/has22.py +++ b/list-2/has22.py @@ -6,4 +6,4 @@ def has22(nums): print(has22([1, 2, 2])) print(has22([1, 2, 1, 2])) -print(has22([2, 1, 2])) \ No newline at end of file +print(has22([2, 1, 2])) diff --git a/list-2/sum13.py b/list-2/sum13.py index 579d8cd..bc5315d 100644 --- a/list-2/sum13.py +++ b/list-2/sum13.py @@ -6,4 +6,4 @@ def sum13(nums): print(sum13([1, 2, 2, 1])) print(sum13([1, 1])) -print(sum13([1, 2, 2, 1, 13])) \ No newline at end of file +print(sum13([1, 2, 2, 1, 13])) diff --git a/list-2/sum67.py b/list-2/sum67.py index ac11498..242ee90 100644 --- a/list-2/sum67.py +++ b/list-2/sum67.py @@ -6,4 +6,4 @@ def sum67(nums): print(sum67([1, 2, 2])) print(sum67([1, 2, 2, 6, 99, 99, 7])) -print(sum67([1, 1, 6, 7, 2])) \ No newline at end of file +print(sum67([1, 1, 6, 7, 2])) diff --git a/logic-1/alarm_clock.py b/logic-1/alarm_clock.py index 1e49966..e7b2976 100644 --- a/logic-1/alarm_clock.py +++ b/logic-1/alarm_clock.py @@ -6,4 +6,4 @@ def alarm_clock(day, vacation): print(alarm_clock(1, False)) print(alarm_clock(5, False)) -print(alarm_clock(0, False)) \ No newline at end of file +print(alarm_clock(0, False)) diff --git a/logic-1/caught_speeding.py b/logic-1/caught_speeding.py index ecd64eb..3d1c566 100644 --- a/logic-1/caught_speeding.py +++ b/logic-1/caught_speeding.py @@ -6,4 +6,4 @@ def caught_speeding(speed, is_birthday): print(caught_speeding(60, False)) print(caught_speeding(65, False)) -print(caught_speeding(65, True)) \ No newline at end of file +print(caught_speeding(65, True)) diff --git a/logic-1/date_fashion.py b/logic-1/date_fashion.py index e70f70b..4e618a0 100644 --- a/logic-1/date_fashion.py +++ b/logic-1/date_fashion.py @@ -6,4 +6,4 @@ def date_fashion(you, date): print(date_fashion(5, 10)) print(date_fashion(5, 2)) -print(date_fashion(5, 5)) \ No newline at end of file +print(date_fashion(5, 5)) diff --git a/logic-1/in1to10.py b/logic-1/in1to10.py index 361eff8..65e3452 100644 --- a/logic-1/in1to10.py +++ b/logic-1/in1to10.py @@ -6,4 +6,4 @@ def in1to10(n, outside_mode): print(in1to10(5, False)) print(in1to10(11, False)) -print(in1to10(11, True)) \ No newline at end of file +print(in1to10(11, True)) diff --git a/logic-1/love6.py b/logic-1/love6.py index 982af84..c705954 100644 --- a/logic-1/love6.py +++ b/logic-1/love6.py @@ -6,4 +6,4 @@ def love6(a, b): print(love6(6, 4)) print(love6(4, 5)) -print(love6(1, 5)) \ No newline at end of file +print(love6(1, 5)) diff --git a/logic-1/near_ten.py b/logic-1/near_ten.py index b5f081a..852a382 100644 --- a/logic-1/near_ten.py +++ b/logic-1/near_ten.py @@ -6,4 +6,4 @@ def near_ten(num): print(near_ten(12)) print(near_ten(17)) -print(near_ten(19)) \ No newline at end of file +print(near_ten(19)) diff --git a/logic-1/sorta_sum.py b/logic-1/sorta_sum.py index ba1e89a..aed9eea 100644 --- a/logic-1/sorta_sum.py +++ b/logic-1/sorta_sum.py @@ -6,4 +6,4 @@ def sorta_sum(a, b): print(sorta_sum(3, 4)) print(sorta_sum(9, 4)) -print(sorta_sum(10, 11)) \ No newline at end of file +print(sorta_sum(10, 11)) diff --git a/logic-1/squirrel_play.py b/logic-1/squirrel_play.py index 99b3ff7..2d3af38 100644 --- a/logic-1/squirrel_play.py +++ b/logic-1/squirrel_play.py @@ -6,4 +6,4 @@ def squirrel_play(temp, is_summer): print(squirrel_play(70, False)) print(squirrel_play(95, False)) -print(squirrel_play(95, True)) \ No newline at end of file +print(squirrel_play(95, True)) diff --git a/logic-2/close_far.py b/logic-2/close_far.py index 859b1b2..2542ff7 100644 --- a/logic-2/close_far.py +++ b/logic-2/close_far.py @@ -6,4 +6,4 @@ def close_far(a, b, c): print(close_far(1, 2, 10)) print(close_far(1, 2, 3)) -print(close_far(4, 1, 3)) \ No newline at end of file +print(close_far(4, 1, 3)) diff --git a/logic-2/lucky_sum.py b/logic-2/lucky_sum.py index 8e759ae..61c8061 100644 --- a/logic-2/lucky_sum.py +++ b/logic-2/lucky_sum.py @@ -6,4 +6,4 @@ def lucky_sum(a, b, c): print(lucky_sum(1, 2, 3)) print(lucky_sum(1, 2, 13)) -print(lucky_sum(1, 13, 3)) \ No newline at end of file +print(lucky_sum(1, 13, 3)) diff --git a/logic-2/make_bricks.py b/logic-2/make_bricks.py index cfb1cdc..c4e199e 100644 --- a/logic-2/make_bricks.py +++ b/logic-2/make_bricks.py @@ -6,4 +6,4 @@ def make_bricks(small, big, goal): print(make_bricks(3, 1, 8)) print(make_bricks(3, 1, 9)) -print(make_bricks(3, 2, 10)) \ No newline at end of file +print(make_bricks(3, 2, 10)) diff --git a/logic-2/make_chocolate.py b/logic-2/make_chocolate.py index e6afa0d..40b3bdd 100644 --- a/logic-2/make_chocolate.py +++ b/logic-2/make_chocolate.py @@ -6,4 +6,4 @@ def make_chocolate(small, big, goal): print(make_chocolate(4, 1, 9)) print(make_chocolate(4, 1, 10)) -print(make_chocolate(4, 1, 7)) \ No newline at end of file +print(make_chocolate(4, 1, 7)) diff --git a/logic-2/no_teen_sum.py b/logic-2/no_teen_sum.py index b2c22d6..a746ed9 100644 --- a/logic-2/no_teen_sum.py +++ b/logic-2/no_teen_sum.py @@ -6,4 +6,4 @@ def no_teen_sum(a, b, c): print(no_teen_sum(1, 2, 3)) print(no_teen_sum(2, 13, 1)) -print(no_teen_sum(2, 1, 14)) \ No newline at end of file +print(no_teen_sum(2, 1, 14)) diff --git a/logic-2/round_sum.py b/logic-2/round_sum.py index 908d69e..528c52d 100644 --- a/logic-2/round_sum.py +++ b/logic-2/round_sum.py @@ -6,4 +6,4 @@ def round_sum(a, b, c): print(round_sum(16, 17, 18)) print(round_sum(12, 13, 14)) -print(round_sum(6, 4, 4)) \ No newline at end of file +print(round_sum(6, 4, 4)) diff --git a/string-1/combo_string.py b/string-1/combo_string.py index 98830ae..18d475c 100644 --- a/string-1/combo_string.py +++ b/string-1/combo_string.py @@ -6,4 +6,4 @@ def combo_string(a, b): print(combo_string('Hello', 'hi')) print(combo_string('hi', 'Hello')) -print(combo_string('aaa', 'b')) \ No newline at end of file +print(combo_string('aaa', 'b')) diff --git a/string-1/extra_end.py b/string-1/extra_end.py index 8b6d5e2..ee9ceb3 100644 --- a/string-1/extra_end.py +++ b/string-1/extra_end.py @@ -6,4 +6,4 @@ def extra_end(str): print(extra_end('Hello')) print(extra_end('ab')) -print(extra_end('Hi')) \ No newline at end of file +print(extra_end('Hi')) diff --git a/string-1/first_half.py b/string-1/first_half.py index 3059880..efb3de3 100644 --- a/string-1/first_half.py +++ b/string-1/first_half.py @@ -6,4 +6,4 @@ def first_half(str): print(first_half('WooHoo')) print(first_half('HelloThere')) -print(first_half('abcdef')) \ No newline at end of file +print(first_half('abcdef')) diff --git a/string-1/first_two.py b/string-1/first_two.py index e1c4c40..5c85508 100644 --- a/string-1/first_two.py +++ b/string-1/first_two.py @@ -6,4 +6,4 @@ def first_two(str): print(first_two('Hello')) print(first_two('abcdefg')) -print(first_two('ab')) \ No newline at end of file +print(first_two('ab')) diff --git a/string-1/left2.py b/string-1/left2.py index 801ccb5..a4d5c6a 100644 --- a/string-1/left2.py +++ b/string-1/left2.py @@ -6,4 +6,4 @@ def left2(str): print(left2('Hello')) print(left2('java')) -print(left2('Hi')) \ No newline at end of file +print(left2('Hi')) diff --git a/string-1/make_abba.py b/string-1/make_abba.py index dc82f47..fbf171b 100644 --- a/string-1/make_abba.py +++ b/string-1/make_abba.py @@ -6,4 +6,4 @@ def make_abba(a, b): print(make_abba('Hi', 'Bye')) print(make_abba('Yo', 'Alice')) -print(make_abba('What', 'Up')) \ No newline at end of file +print(make_abba('What', 'Up')) diff --git a/string-1/make_out_word.py b/string-1/make_out_word.py index 3c13cad..dccc5c7 100644 --- a/string-1/make_out_word.py +++ b/string-1/make_out_word.py @@ -6,4 +6,4 @@ def make_out_word(out, word): print(make_out_word('<<>>', 'Yay')) print(make_out_word('<<>>', 'WooHoo')) -print(make_out_word('[[]]', 'word')) \ No newline at end of file +print(make_out_word('[[]]', 'word')) diff --git a/string-1/make_tags.py b/string-1/make_tags.py index 52949d7..c94ac27 100644 --- a/string-1/make_tags.py +++ b/string-1/make_tags.py @@ -6,4 +6,4 @@ def make_tags(tag, word): print(make_tags('i', 'Yay')) print(make_tags('i', 'Hello')) -print(make_tags('cite', 'Yay')) \ No newline at end of file +print(make_tags('cite', 'Yay')) diff --git a/string-1/non_start.py b/string-1/non_start.py index badb7b3..6622702 100644 --- a/string-1/non_start.py +++ b/string-1/non_start.py @@ -6,4 +6,4 @@ def non_start(a, b): print(non_start('Hello', 'There')) print(non_start('java', 'code')) -print(non_start('shotl', 'java')) \ No newline at end of file +print(non_start('shotl', 'java')) diff --git a/string-1/without_end.py b/string-1/without_end.py index 9fe8072..47a9405 100644 --- a/string-1/without_end.py +++ b/string-1/without_end.py @@ -6,4 +6,4 @@ def without_end(str): print(without_end('Hello')) print(without_end('java')) -print(without_end('coding')) \ No newline at end of file +print(without_end('coding')) diff --git a/string-2/cat_dog.py b/string-2/cat_dog.py index b619ab4..6bc1289 100644 --- a/string-2/cat_dog.py +++ b/string-2/cat_dog.py @@ -6,4 +6,4 @@ def cat_dog(str): print(cat_dog('catdog')) print(cat_dog('catcat')) -print(cat_dog('1cat1cadodog')) \ No newline at end of file +print(cat_dog('1cat1cadodog')) diff --git a/string-2/count_code.py b/string-2/count_code.py index 4f14ba7..de99db8 100644 --- a/string-2/count_code.py +++ b/string-2/count_code.py @@ -6,4 +6,4 @@ def count_code(str): print(count_code('aaacodebbb')) print(count_code('codexxcode')) -print(count_code('cozexxcope')) \ No newline at end of file +print(count_code('cozexxcope')) diff --git a/string-2/count_hi.py b/string-2/count_hi.py index 38803b4..f0afce7 100644 --- a/string-2/count_hi.py +++ b/string-2/count_hi.py @@ -6,4 +6,4 @@ def count_hi(str): print(count_hi('abc hi ho')) print(count_hi('ABChi hi')) -print(count_hi('hihi')) \ No newline at end of file +print(count_hi('hihi')) diff --git a/string-2/end_other.py b/string-2/end_other.py index 12ed685..37e32b0 100644 --- a/string-2/end_other.py +++ b/string-2/end_other.py @@ -6,4 +6,4 @@ def end_other(a, b): print(end_other('Hiabc', 'abc')) print(end_other('AbC', 'HiaBc')) -print(end_other('abc', 'abXabc')) \ No newline at end of file +print(end_other('abc', 'abXabc')) diff --git a/string-2/xyz_there.py b/string-2/xyz_there.py index b78dd9f..dbb040f 100644 --- a/string-2/xyz_there.py +++ b/string-2/xyz_there.py @@ -6,4 +6,4 @@ def xyz_there(str): print(xyz_there('abcxyz')) print(xyz_there('abc.xyz')) -print(xyz_there('xyz.abc')) \ No newline at end of file +print(xyz_there('xyz.abc')) diff --git a/warmup-1/diff21.py b/warmup-1/diff21.py index 38c98fd..23f9c7e 100644 --- a/warmup-1/diff21.py +++ b/warmup-1/diff21.py @@ -6,4 +6,4 @@ def diff21(n): print(diff21(19)) print(diff21(10)) -print(diff21(21)) \ No newline at end of file +print(diff21(21)) diff --git a/warmup-1/front3.py b/warmup-1/front3.py index 03c3e61..5492ca7 100644 --- a/warmup-1/front3.py +++ b/warmup-1/front3.py @@ -6,4 +6,4 @@ def front3(str): print(front3('Java')) print(front3('Chocolate')) -print(front3('abc')) \ No newline at end of file +print(front3('abc')) diff --git a/warmup-1/front_back.py b/warmup-1/front_back.py index 109bc73..bfb2594 100644 --- a/warmup-1/front_back.py +++ b/warmup-1/front_back.py @@ -6,4 +6,4 @@ def front_back(str): print(front_back('code')) print(front_back('a')) -print(front_back('ab')) \ No newline at end of file +print(front_back('ab')) diff --git a/warmup-1/makes10.py b/warmup-1/makes10.py index e24ae98..751c0df 100644 --- a/warmup-1/makes10.py +++ b/warmup-1/makes10.py @@ -6,4 +6,4 @@ def makes10(a, b): print(makes10(9, 10)) print(makes10(9, 9)) -print(makes10(1, 9)) \ No newline at end of file +print(makes10(1, 9)) diff --git a/warmup-1/missing_char.py b/warmup-1/missing_char.py index bfc9966..3ec7896 100644 --- a/warmup-1/missing_char.py +++ b/warmup-1/missing_char.py @@ -6,4 +6,4 @@ def missing_char(str, n): print(missing_char('kitten', 1)) print(missing_char('kitten', 0)) -print(missing_char('kitten', 4)) \ No newline at end of file +print(missing_char('kitten', 4)) diff --git a/warmup-1/monkey_trouble.py b/warmup-1/monkey_trouble.py index 3c54c55..b1bca90 100644 --- a/warmup-1/monkey_trouble.py +++ b/warmup-1/monkey_trouble.py @@ -6,4 +6,4 @@ def monkey_trouble(a_smile, b_smile): print(monkey_trouble(True, True)) print(monkey_trouble(False, False)) -print(monkey_trouble(True, False)) \ No newline at end of file +print(monkey_trouble(True, False)) diff --git a/warmup-1/near_hundred.py b/warmup-1/near_hundred.py index 4bc7daf..a752aed 100644 --- a/warmup-1/near_hundred.py +++ b/warmup-1/near_hundred.py @@ -6,4 +6,4 @@ def near_hundred(n): print(near_hundred(93)) print(near_hundred(90)) -print(near_hundred(89)) \ No newline at end of file +print(near_hundred(89)) diff --git a/warmup-1/not_string.py b/warmup-1/not_string.py index 466304b..b4fcd73 100644 --- a/warmup-1/not_string.py +++ b/warmup-1/not_string.py @@ -6,4 +6,4 @@ def not_string(str): print(not_string('candy')) print(not_string('x')) -print(not_string('not bad')) \ No newline at end of file +print(not_string('not bad')) diff --git a/warmup-1/parrot_trouble.py b/warmup-1/parrot_trouble.py index a4db2a8..b657255 100644 --- a/warmup-1/parrot_trouble.py +++ b/warmup-1/parrot_trouble.py @@ -6,4 +6,4 @@ def parrot_trouble(talking, hour): print(parrot_trouble(True, 6)) print(parrot_trouble(True, 7)) -print(parrot_trouble(False, 6)) \ No newline at end of file +print(parrot_trouble(False, 6)) diff --git a/warmup-1/pos_neg.py b/warmup-1/pos_neg.py index 571d45c..9fa91f6 100644 --- a/warmup-1/pos_neg.py +++ b/warmup-1/pos_neg.py @@ -6,4 +6,4 @@ def pos_neg(a, b, negative): print(pos_neg(1, -1, False)) print(pos_neg(-1, 1, False)) -print(pos_neg(-4, -5, True)) \ No newline at end of file +print(pos_neg(-4, -5, True)) diff --git a/warmup-1/sum_double.py b/warmup-1/sum_double.py index c3e8892..5f09d62 100644 --- a/warmup-1/sum_double.py +++ b/warmup-1/sum_double.py @@ -6,4 +6,4 @@ def sum_double(a, b): print(sum_double(1, 2)) print(sum_double(3, 2)) -print(sum_double(2, 2)) \ No newline at end of file +print(sum_double(2, 2)) diff --git a/warmup-2/array123.py b/warmup-2/array123.py index 7271fdf..ff53521 100644 --- a/warmup-2/array123.py +++ b/warmup-2/array123.py @@ -6,4 +6,4 @@ def array123(nums): print(array123([1, 1, 2, 3, 1])) print(array123([1, 1, 2, 4, 1])) -print(array123([1, 1, 2, 1, 2, 3])) \ No newline at end of file +print(array123([1, 1, 2, 1, 2, 3])) diff --git a/warmup-2/array_count9.py b/warmup-2/array_count9.py index 9d0b975..6cdf1d0 100644 --- a/warmup-2/array_count9.py +++ b/warmup-2/array_count9.py @@ -6,4 +6,4 @@ def array_count9(nums): print(array_count9([1, 2, 9])) print(array_count9([1, 9, 9])) -print(array_count9([1, 9, 9, 3, 9])) \ No newline at end of file +print(array_count9([1, 9, 9, 3, 9])) diff --git a/warmup-2/array_front9.py b/warmup-2/array_front9.py index 228f087..a754d1b 100644 --- a/warmup-2/array_front9.py +++ b/warmup-2/array_front9.py @@ -6,4 +6,4 @@ def array_front9(nums): print(array_front9([1, 2, 9, 3, 4])) print(array_front9([1, 2, 3, 4, 9])) -print(array_front9([1, 2, 3, 4, 5])) \ No newline at end of file +print(array_front9([1, 2, 3, 4, 5])) diff --git a/warmup-2/front_times.py b/warmup-2/front_times.py index 767b765..f80f20f 100644 --- a/warmup-2/front_times.py +++ b/warmup-2/front_times.py @@ -6,4 +6,4 @@ def front_times(str, n): print(front_times('Chocolate', 2)) print(front_times('Chocolate', 3)) -print(front_times('Abc', 3)) \ No newline at end of file +print(front_times('Abc', 3)) diff --git a/warmup-2/last2.py b/warmup-2/last2.py index 5c3ea24..fe04d70 100644 --- a/warmup-2/last2.py +++ b/warmup-2/last2.py @@ -6,4 +6,4 @@ def last2(str): print(last2('hixxhi')) print(last2('xaxxaxaxx')) -print(last2('axxxaaxx')) \ No newline at end of file +print(last2('axxxaaxx')) diff --git a/warmup-2/string_bits.py b/warmup-2/string_bits.py index 0588eef..9e83bf7 100644 --- a/warmup-2/string_bits.py +++ b/warmup-2/string_bits.py @@ -6,4 +6,4 @@ def string_bits(str): print(string_bits('Hello')) print(string_bits('Hi')) -print(string_bits('Heeololeo')) \ No newline at end of file +print(string_bits('Heeololeo')) diff --git a/warmup-2/string_match.py b/warmup-2/string_match.py index 95d6f26..f813d3f 100644 --- a/warmup-2/string_match.py +++ b/warmup-2/string_match.py @@ -6,4 +6,4 @@ def string_match(a, b): print(string_match('xxcaazz', 'xxbaaz')) print(string_match('abc', 'abc')) -print(string_match('abc', 'axc')) \ No newline at end of file +print(string_match('abc', 'axc')) diff --git a/warmup-2/string_splosion.py b/warmup-2/string_splosion.py index 7843ce5..970d78b 100644 --- a/warmup-2/string_splosion.py +++ b/warmup-2/string_splosion.py @@ -6,4 +6,4 @@ def string_splosion(str): print(string_splosion('Code')) print(string_splosion('abc')) -print(string_splosion('ab')) \ No newline at end of file +print(string_splosion('ab')) From f8d7ab4699f2d9e9b6b05e704291b336bea1221f Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Thu, 11 Oct 2018 14:38:37 -0400 Subject: [PATCH 3/7] Complete warmup 1 and warmup 2 --- warmup-1/diff21.py | 4 +++- warmup-1/front3.py | 2 +- warmup-1/front_back.py | 4 +++- warmup-1/makes10.py | 2 +- warmup-1/missing_char.py | 2 +- warmup-1/monkey_trouble.py | 2 +- warmup-1/near_hundred.py | 2 +- warmup-1/not_string.py | 4 +++- warmup-1/parrot_trouble.py | 2 +- warmup-1/pos_neg.py | 5 ++++- warmup-1/sum_double.py | 4 +++- warmup-2/array123.py | 5 ++++- warmup-2/array_count9.py | 2 +- warmup-2/array_front9.py | 2 +- warmup-2/front_times.py | 2 +- warmup-2/last2.py | 10 +++++++++- warmup-2/string_bits.py | 5 ++++- warmup-2/string_match.py | 6 +++++- warmup-2/string_splosion.py | 5 ++++- 19 files changed, 51 insertions(+), 19 deletions(-) diff --git a/warmup-1/diff21.py b/warmup-1/diff21.py index 23f9c7e..daf8904 100644 --- a/warmup-1/diff21.py +++ b/warmup-1/diff21.py @@ -2,7 +2,9 @@ def diff21(n): """ Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21. """ - pass + if n> 21: + return (n- 21) * 2 + return 21 - n print(diff21(19)) print(diff21(10)) diff --git a/warmup-1/front3.py b/warmup-1/front3.py index 5492ca7..43185e1 100644 --- a/warmup-1/front3.py +++ b/warmup-1/front3.py @@ -2,7 +2,7 @@ def front3(str): """ Given a string, we'll say that the front is the first 3 chars of the string. If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front. """ - pass + return str[0:3]*3 print(front3('Java')) print(front3('Chocolate')) diff --git a/warmup-1/front_back.py b/warmup-1/front_back.py index bfb2594..55455b7 100644 --- a/warmup-1/front_back.py +++ b/warmup-1/front_back.py @@ -2,7 +2,9 @@ def front_back(str): """ Given a string, return a new string where the first and last chars have been exchanged. """ - pass + if len(str) > 1: + return str[-1] + str[1:-1] + str[0] + return str print(front_back('code')) print(front_back('a')) diff --git a/warmup-1/makes10.py b/warmup-1/makes10.py index 751c0df..19d80d7 100644 --- a/warmup-1/makes10.py +++ b/warmup-1/makes10.py @@ -2,7 +2,7 @@ def makes10(a, b): """ Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10. """ - pass + return a == 10 or b == 10 or a + b == 10 print(makes10(9, 10)) print(makes10(9, 9)) diff --git a/warmup-1/missing_char.py b/warmup-1/missing_char.py index 3ec7896..8b4272b 100644 --- a/warmup-1/missing_char.py +++ b/warmup-1/missing_char.py @@ -2,7 +2,7 @@ def missing_char(str, n): """ Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..len(str)-1 inclusive). """ - pass + return str[:n] + str[n + 1:] print(missing_char('kitten', 1)) print(missing_char('kitten', 0)) diff --git a/warmup-1/monkey_trouble.py b/warmup-1/monkey_trouble.py index b1bca90..31dc6bf 100644 --- a/warmup-1/monkey_trouble.py +++ b/warmup-1/monkey_trouble.py @@ -2,7 +2,7 @@ def monkey_trouble(a_smile, b_smile): """ We have two monkeys, a and b, and the parameters a_smile and b_smile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return True if we are in trouble. """ - pass + return a_smile == b_smile print(monkey_trouble(True, True)) print(monkey_trouble(False, False)) diff --git a/warmup-1/near_hundred.py b/warmup-1/near_hundred.py index a752aed..e9218c2 100644 --- a/warmup-1/near_hundred.py +++ b/warmup-1/near_hundred.py @@ -2,7 +2,7 @@ def near_hundred(n): """ Given an int n, return True if it is within 10 of 100 or 200. Note: abs(num) computes the absolute value of a number. """ - pass + return abs(200 - n) <= 10 or abs(100 - n) <= 10 print(near_hundred(93)) print(near_hundred(90)) diff --git a/warmup-1/not_string.py b/warmup-1/not_string.py index b4fcd73..aa2092c 100644 --- a/warmup-1/not_string.py +++ b/warmup-1/not_string.py @@ -2,7 +2,9 @@ def not_string(str): """ Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. """ - pass + if 'not' == str[:3]: + return str + return 'not ' + str print(not_string('candy')) print(not_string('x')) diff --git a/warmup-1/parrot_trouble.py b/warmup-1/parrot_trouble.py index b657255..031f50e 100644 --- a/warmup-1/parrot_trouble.py +++ b/warmup-1/parrot_trouble.py @@ -2,7 +2,7 @@ def parrot_trouble(talking, hour): """ We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return True if we are in trouble. """ - pass + return talking and (hour < 7 or hour> 20) print(parrot_trouble(True, 6)) print(parrot_trouble(True, 7)) diff --git a/warmup-1/pos_neg.py b/warmup-1/pos_neg.py index 9fa91f6..93282b2 100644 --- a/warmup-1/pos_neg.py +++ b/warmup-1/pos_neg.py @@ -2,7 +2,10 @@ def pos_neg(a, b, negative): """ Given 2 int values, return True if one is negative and one is positive. Except if the parameter "negative" is True, then return True only if both are negative. """ - pass + if negative: + return a < 0 and b < 0 + else : + return (a < 0 and b > 0) or (a > 0 and b < 0) print(pos_neg(1, -1, False)) print(pos_neg(-1, 1, False)) diff --git a/warmup-1/sum_double.py b/warmup-1/sum_double.py index 5f09d62..eef5080 100644 --- a/warmup-1/sum_double.py +++ b/warmup-1/sum_double.py @@ -2,7 +2,9 @@ def sum_double(a, b): """ Given two int values, return their sum. Unless the two values are the same, then return double their sum. """ - pass + if a == b: + return (a + b ) * 2 + return a + b print(sum_double(1, 2)) print(sum_double(3, 2)) diff --git a/warmup-2/array123.py b/warmup-2/array123.py index ff53521..8ecca64 100644 --- a/warmup-2/array123.py +++ b/warmup-2/array123.py @@ -2,7 +2,10 @@ def array123(nums): """ Given an array of ints, return True if the sequence of numbers 1, 2, 3 appears in the array somewhere. """ - pass + for i in range(len(nums)- 2): + if nums[i] == 1 and nums[i + 1] == 2 and nums[i + 2] == 3: + return True + return False print(array123([1, 1, 2, 3, 1])) print(array123([1, 1, 2, 4, 1])) diff --git a/warmup-2/array_count9.py b/warmup-2/array_count9.py index 6cdf1d0..98b5807 100644 --- a/warmup-2/array_count9.py +++ b/warmup-2/array_count9.py @@ -2,7 +2,7 @@ def array_count9(nums): """ Given an array of ints, return the number of 9's in the array. """ - pass + return nums.count(9) print(array_count9([1, 2, 9])) print(array_count9([1, 9, 9])) diff --git a/warmup-2/array_front9.py b/warmup-2/array_front9.py index a754d1b..6df18a1 100644 --- a/warmup-2/array_front9.py +++ b/warmup-2/array_front9.py @@ -2,7 +2,7 @@ def array_front9(nums): """ Given an array of ints, return True if one of the first 4 elements in the array is a 9. The array length may be less than 4. """ - pass + return 9 in nums[:4] print(array_front9([1, 2, 9, 3, 4])) print(array_front9([1, 2, 3, 4, 9])) diff --git a/warmup-2/front_times.py b/warmup-2/front_times.py index f80f20f..cc2a3c2 100644 --- a/warmup-2/front_times.py +++ b/warmup-2/front_times.py @@ -2,7 +2,7 @@ def front_times(str, n): """ Given a string and a non-negative int n, we'll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front; """ - pass + return str[:3] * n print(front_times('Chocolate', 2)) print(front_times('Chocolate', 3)) diff --git a/warmup-2/last2.py b/warmup-2/last2.py index fe04d70..8eb43f8 100644 --- a/warmup-2/last2.py +++ b/warmup-2/last2.py @@ -2,7 +2,15 @@ def last2(str): """ Given a string, return the count of the number of times that a substring length 2 appears in the string and also as the last 2 chars of the string, so "hixxxhi" yields 1 (we won't count the end substring). """ - pass + if len(str) < 2: + return 0 + last2 = str[-2:] + count = 0 + for i in range(len(str) - 2): + if str[i] == last2[0] and str[i + 1] == last2[1]: + count += 1 + return count + print(last2('hixxhi')) print(last2('xaxxaxaxx')) diff --git a/warmup-2/string_bits.py b/warmup-2/string_bits.py index 9e83bf7..a0c8023 100644 --- a/warmup-2/string_bits.py +++ b/warmup-2/string_bits.py @@ -2,7 +2,10 @@ def string_bits(str): """ Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo". """ - pass + return_str = '' + for i in range(0, len(str), 2): + return_str += str[i] + return return_str print(string_bits('Hello')) print(string_bits('Hi')) diff --git a/warmup-2/string_match.py b/warmup-2/string_match.py index f813d3f..b3ab02d 100644 --- a/warmup-2/string_match.py +++ b/warmup-2/string_match.py @@ -2,7 +2,11 @@ def string_match(a, b): """ Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. """ - pass + count = 0 + for i in range(0, len(a) - 1): + if a[i:i+2] == b[i:i+2]: + count += 1 + return count print(string_match('xxcaazz', 'xxbaaz')) print(string_match('abc', 'abc')) diff --git a/warmup-2/string_splosion.py b/warmup-2/string_splosion.py index 970d78b..99e9a5f 100644 --- a/warmup-2/string_splosion.py +++ b/warmup-2/string_splosion.py @@ -2,7 +2,10 @@ def string_splosion(str): """ Given a non-empty string like "Code" return a string like "CCoCodCode". """ - pass + string = '' + for i in range(len(str)): + string += str[0:i+1] + return string print(string_splosion('Code')) print(string_splosion('abc')) From b7be6f77de38c15b09a55453c8ab7391ac4572f9 Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Thu, 11 Oct 2018 15:02:16 -0400 Subject: [PATCH 4/7] Add install instructions for scraper --- codingbat_exercise_scraper.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codingbat_exercise_scraper.py b/codingbat_exercise_scraper.py index bebd358..7cf8569 100644 --- a/codingbat_exercise_scraper.py +++ b/codingbat_exercise_scraper.py @@ -1,6 +1,12 @@ """ This script gets all the exercises in codingbat and creates a base file in the appropriate folder to edit. +You need to install requests and bs4. + +You can do the following to install: +pip install bs4 +pip install requests + Author: Ha Min Ko """ From b9060b438e4047d17ba4def205a1eec4022a39e4 Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Mon, 22 Oct 2018 17:36:20 -0400 Subject: [PATCH 5/7] String1 and List1 --- list-1/common_end.py | 2 +- list-1/has23.py | 2 +- list-1/make_ends.py | 2 +- list-1/make_pi.py | 2 +- list-1/max_end3.py | 2 +- list-1/middle_way.py | 2 +- list-1/reverse3.py | 2 +- list-1/rotate_left3.py | 4 ++-- list-1/same_first_last.py | 2 +- list-1/sum2.py | 2 +- list-1/sum3.py | 2 +- string-1/combo_string.py | 8 +++++++- string-1/extra_end.py | 2 +- string-1/first_half.py | 2 +- string-1/first_two.py | 2 +- string-1/left2.py | 2 +- string-1/make_abba.py | 2 +- string-1/make_out_word.py | 2 +- string-1/make_tags.py | 2 +- string-1/non_start.py | 2 +- string-1/without_end.py | 2 +- 21 files changed, 28 insertions(+), 22 deletions(-) diff --git a/list-1/common_end.py b/list-1/common_end.py index a74182e..6d85484 100644 --- a/list-1/common_end.py +++ b/list-1/common_end.py @@ -2,7 +2,7 @@ def common_end(a, b): """ Given 2 arrays of ints, a and b, return True if they have the same first element or they have the same last element. Both arrays will be length 1 or more. """ - pass + return a[-1] == b[-1] or a[0] == b[0] print(common_end([1, 2, 3], [7, 3])) print(common_end([1, 2, 3], [7, 3, 2])) diff --git a/list-1/has23.py b/list-1/has23.py index 10231dd..c79a3dc 100644 --- a/list-1/has23.py +++ b/list-1/has23.py @@ -2,7 +2,7 @@ def has23(nums): """ Given an int array length 2, return True if it contains a 2 or a 3. """ - pass + return 2 in nums or 3 in nums print(has23([2, 5])) print(has23([4, 3])) diff --git a/list-1/make_ends.py b/list-1/make_ends.py index 0d45378..fbb08d8 100644 --- a/list-1/make_ends.py +++ b/list-1/make_ends.py @@ -2,7 +2,7 @@ def make_ends(nums): """ Given an array of ints, return a new array length 2 containing the first and last elements from the original array. The original array will be length 1 or more. """ - pass + return [nums[0], nums[-1]] print(make_ends([1, 2, 3])) print(make_ends([1, 2, 3, 4])) diff --git a/list-1/make_pi.py b/list-1/make_pi.py index 2af7e09..f59b128 100644 --- a/list-1/make_pi.py +++ b/list-1/make_pi.py @@ -2,6 +2,6 @@ def make_pi(): """ Return an int array length 3 containing the first 3 digits of pi, {3, 1, 4}. """ - pass + return [3, 1, 4] print(make_pi()) diff --git a/list-1/max_end3.py b/list-1/max_end3.py index 5cbf830..aa6b865 100644 --- a/list-1/max_end3.py +++ b/list-1/max_end3.py @@ -2,7 +2,7 @@ def max_end3(nums): """ Given an array of ints length 3, figure out which is larger, the first or last element in the array, and set all the other elements to be that value. Return the changed array. """ - pass + return [max(nums[0], nums[-1]) for x in nums] print(max_end3([1, 2, 3])) print(max_end3([11, 5, 9])) diff --git a/list-1/middle_way.py b/list-1/middle_way.py index 73eb5f6..67e5a0d 100644 --- a/list-1/middle_way.py +++ b/list-1/middle_way.py @@ -2,7 +2,7 @@ def middle_way(a, b): """ Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements. """ - pass + return [a[1], b[1]] print(middle_way([1, 2, 3], [4, 5, 6])) print(middle_way([7, 7, 7], [3, 8, 0])) diff --git a/list-1/reverse3.py b/list-1/reverse3.py index eb83b54..76d6fd7 100644 --- a/list-1/reverse3.py +++ b/list-1/reverse3.py @@ -2,7 +2,7 @@ def reverse3(nums): """ Given an array of ints length 3, return a new array with the elements in reverse order, so {1, 2, 3} becomes {3, 2, 1}. """ - pass + return [::-1] print(reverse3([1, 2, 3])) print(reverse3([5, 11, 9])) diff --git a/list-1/rotate_left3.py b/list-1/rotate_left3.py index 4563da9..77fc596 100644 --- a/list-1/rotate_left3.py +++ b/list-1/rotate_left3.py @@ -2,8 +2,8 @@ def rotate_left3(nums): """ Given an array of ints length 3, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}. """ - pass - + return nums[1:] + nums[:1] + print(rotate_left3([1, 2, 3])) print(rotate_left3([5, 11, 9])) print(rotate_left3([7, 0, 0])) diff --git a/list-1/same_first_last.py b/list-1/same_first_last.py index 1e3717c..5bc04cd 100644 --- a/list-1/same_first_last.py +++ b/list-1/same_first_last.py @@ -2,7 +2,7 @@ def same_first_last(nums): """ Given an array of ints, return True if the array is length 1 or more, and the first element and the last element are equal. """ - pass + return len(nums) >= 1 and nums[0] == nums[-1] print(same_first_last([1, 2, 3])) print(same_first_last([1, 2, 3, 1])) diff --git a/list-1/sum2.py b/list-1/sum2.py index df30702..61b4e86 100644 --- a/list-1/sum2.py +++ b/list-1/sum2.py @@ -2,7 +2,7 @@ def sum2(nums): """ Given an array of ints, return the sum of the first 2 elements in the array. If the array length is less than 2, just sum up the elements that exist, returning 0 if the array is length 0. """ - pass + return sum(nums[0:2]) print(sum2([1, 2, 3])) print(sum2([1, 1])) diff --git a/list-1/sum3.py b/list-1/sum3.py index a98c246..603b9b3 100644 --- a/list-1/sum3.py +++ b/list-1/sum3.py @@ -2,7 +2,7 @@ def sum3(nums): """ Given an array of ints length 3, return the sum of all the elements. """ - pass + return sum(nums) print(sum3([1, 2, 3])) print(sum3([5, 11, 2])) diff --git a/string-1/combo_string.py b/string-1/combo_string.py index 18d475c..b1ab906 100644 --- a/string-1/combo_string.py +++ b/string-1/combo_string.py @@ -2,7 +2,13 @@ def combo_string(a, b): """ Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0). """ - pass + if len(a) > len(b): + shorter = b + longer = a + else: + shorter = a + longer = b + return shorter+longer+shorter print(combo_string('Hello', 'hi')) print(combo_string('hi', 'Hello')) diff --git a/string-1/extra_end.py b/string-1/extra_end.py index ee9ceb3..36b144d 100644 --- a/string-1/extra_end.py +++ b/string-1/extra_end.py @@ -2,7 +2,7 @@ def extra_end(str): """ Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2. """ - pass + return str[-2:]*3 print(extra_end('Hello')) print(extra_end('ab')) diff --git a/string-1/first_half.py b/string-1/first_half.py index efb3de3..f5ae147 100644 --- a/string-1/first_half.py +++ b/string-1/first_half.py @@ -2,7 +2,7 @@ def first_half(str): """ Given a string of even length, return the first half. So the string "WooHoo" yields "Woo". """ - pass + return str[0:len(str)/2] print(first_half('WooHoo')) print(first_half('HelloThere')) diff --git a/string-1/first_two.py b/string-1/first_two.py index 5c85508..878b00b 100644 --- a/string-1/first_two.py +++ b/string-1/first_two.py @@ -2,7 +2,7 @@ def first_two(str): """ Given a string, return the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there is, so "X" yields "X", and the empty string "" yields the empty string "". """ - pass + return str[0:2] print(first_two('Hello')) print(first_two('abcdefg')) diff --git a/string-1/left2.py b/string-1/left2.py index a4d5c6a..188bf09 100644 --- a/string-1/left2.py +++ b/string-1/left2.py @@ -2,7 +2,7 @@ def left2(str): """ Given a string, return a "rotated left 2" version where the first 2 chars are moved to the end. The string length will be at least 2. """ - pass + return str[2:] + str[0:2] print(left2('Hello')) print(left2('java')) diff --git a/string-1/make_abba.py b/string-1/make_abba.py index fbf171b..5c47412 100644 --- a/string-1/make_abba.py +++ b/string-1/make_abba.py @@ -2,7 +2,7 @@ def make_abba(a, b): """ Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi". """ - pass + return a + b + b + a print(make_abba('Hi', 'Bye')) print(make_abba('Yo', 'Alice')) diff --git a/string-1/make_out_word.py b/string-1/make_out_word.py index dccc5c7..13e9971 100644 --- a/string-1/make_out_word.py +++ b/string-1/make_out_word.py @@ -2,7 +2,7 @@ def make_out_word(out, word): """ Given an "out" string length 4, such as "<<>>", and a word, return a new string where the word is in the middle of the out string, e.g. "<>". """ - pass + return out[0:2] + word + out[2:] print(make_out_word('<<>>', 'Yay')) print(make_out_word('<<>>', 'WooHoo')) diff --git a/string-1/make_tags.py b/string-1/make_tags.py index c94ac27..c6cc2fe 100644 --- a/string-1/make_tags.py +++ b/string-1/make_tags.py @@ -2,7 +2,7 @@ def make_tags(tag, word): """ The web is built with HTML strings like "Yay" which draws Yay as italic text. In this example, the "i" tag makes and which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "Yay". """ - pass + return '<' + tag + '>' + word + '' print(make_tags('i', 'Yay')) print(make_tags('i', 'Hello')) diff --git a/string-1/non_start.py b/string-1/non_start.py index 6622702..9f3017d 100644 --- a/string-1/non_start.py +++ b/string-1/non_start.py @@ -2,7 +2,7 @@ def non_start(a, b): """ Given 2 strings, return their concatenation, except omit the first char of each. The strings will be at least length 1. """ - pass + return a[1:] + b[1:] print(non_start('Hello', 'There')) print(non_start('java', 'code')) diff --git a/string-1/without_end.py b/string-1/without_end.py index 47a9405..8099e4f 100644 --- a/string-1/without_end.py +++ b/string-1/without_end.py @@ -2,7 +2,7 @@ def without_end(str): """ Given a string, return a version without the first and last char, so "Hello" yields "ell". The string length will be at least 2. """ - pass + return str[1:len(str)-1] print(without_end('Hello')) print(without_end('java')) From be2005424e35df78c3eaf53f48b7d02f5257d2c1 Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Mon, 22 Oct 2018 17:37:25 -0400 Subject: [PATCH 6/7] Update list-1/reverse3.py --- list-1/reverse3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/list-1/reverse3.py b/list-1/reverse3.py index 76d6fd7..5b56645 100644 --- a/list-1/reverse3.py +++ b/list-1/reverse3.py @@ -2,8 +2,8 @@ def reverse3(nums): """ Given an array of ints length 3, return a new array with the elements in reverse order, so {1, 2, 3} becomes {3, 2, 1}. """ - return [::-1] + return nums[::-1] print(reverse3([1, 2, 3])) print(reverse3([5, 11, 9])) -print(reverse3([7, 0, 0])) +print(reverse3([7, 0, 0])) \ No newline at end of file From 2d721c27bf30a2bc40d4bd0d91e77265200e3605 Mon Sep 17 00:00:00 2001 From: Ha Min Ko Date: Mon, 22 Oct 2018 20:08:07 -0400 Subject: [PATCH 7/7] Finish codingbat challenge --- list-2/big_diff.py | 2 +- list-2/centered_average.py | 3 ++- list-2/has22.py | 5 ++++- list-2/sum13.py | 12 +++++++++++- list-2/sum67.py | 11 ++++++++++- logic-1/alarm_clock.py | 9 ++++++++- logic-1/caught_speeding.py | 15 ++++++++++++++- logic-1/date_fashion.py | 7 ++++++- logic-1/in1to10.py | 2 +- logic-1/love6.py | 2 +- logic-1/near_ten.py | 2 +- logic-1/sorta_sum.py | 5 ++++- logic-1/squirrel_play.py | 2 +- logic-2/close_far.py | 2 +- logic-2/lucky_sum.py | 7 ++++++- logic-2/make_bricks.py | 2 +- logic-2/make_chocolate.py | 8 +++++++- logic-2/no_teen_sum.py | 8 +++++++- logic-2/round_sum.py | 8 +++++++- string-2/cat_dog.py | 2 +- string-2/count_code.py | 6 +++++- string-2/count_hi.py | 2 +- string-2/end_other.py | 2 +- string-2/xyz_there.py | 7 ++++++- 24 files changed, 107 insertions(+), 24 deletions(-) diff --git a/list-2/big_diff.py b/list-2/big_diff.py index 34b4e33..765843e 100644 --- a/list-2/big_diff.py +++ b/list-2/big_diff.py @@ -2,7 +2,7 @@ def big_diff(nums): """ Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. Note: the built-in min(v1, v2) and max(v1, v2) functions return the smaller or larger of two values. """ - pass + return max(nums) - min(nums) print(big_diff([10, 3, 5, 6])) print(big_diff([7, 2, 10, 9])) diff --git a/list-2/centered_average.py b/list-2/centered_average.py index 79df72e..0645a38 100644 --- a/list-2/centered_average.py +++ b/list-2/centered_average.py @@ -2,7 +2,8 @@ def centered_average(nums): """ Return the "centered" average of an array of ints, which we'll say is the mean average of the values, except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use int division to produce the final average. You may assume that the array is length 3 or more. """ - pass + sort_nums = sorted(nums) + return sum(sort_nums[1:-1])/len(sort_nums[1:-1]) print(centered_average([1, 2, 3, 4, 100])) print(centered_average([1, 1, 5, 5, 10, 8, 7])) diff --git a/list-2/has22.py b/list-2/has22.py index 7e932d0..7b80a32 100644 --- a/list-2/has22.py +++ b/list-2/has22.py @@ -2,7 +2,10 @@ def has22(nums): """ Given an array of ints, return True if the array contains a 2 next to a 2 somewhere. """ - pass + for i in range(len(nums) - 1): + if nums[i] == 2 and nums[i+1] == 2: + return True + return False print(has22([1, 2, 2])) print(has22([1, 2, 1, 2])) diff --git a/list-2/sum13.py b/list-2/sum13.py index bc5315d..bef462d 100644 --- a/list-2/sum13.py +++ b/list-2/sum13.py @@ -2,7 +2,17 @@ def sum13(nums): """ Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count. """ - pass + total = 0 + is_after_13 = 0 + for i in range(len(nums)): + if is_after_13 == 0 and nums[i] != 13: + total += nums[i] + elif nums[i] == 13: + is_after_13 = 1 + else: + is_after_13 = 0 + return total + print(sum13([1, 2, 2, 1])) print(sum13([1, 1])) diff --git a/list-2/sum67.py b/list-2/sum67.py index 242ee90..a8b7862 100644 --- a/list-2/sum67.py +++ b/list-2/sum67.py @@ -2,7 +2,16 @@ def sum67(nums): """ Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers. """ - pass + total = 0 + is_after_6 = 0 + for i in range(len(nums)): + if nums[i] == 6: + is_after_6 = 1 + elif nums[i] == 7 and is_after_6 == 1: + is_after_6 = 0 + elif is_after_6 != 1: + total += nums[i] + return total print(sum67([1, 2, 2])) print(sum67([1, 2, 2, 6, 99, 99, 7])) diff --git a/logic-1/alarm_clock.py b/logic-1/alarm_clock.py index e7b2976..e7e8936 100644 --- a/logic-1/alarm_clock.py +++ b/logic-1/alarm_clock.py @@ -2,7 +2,14 @@ def alarm_clock(day, vacation): """ Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off". """ - pass + if day in [1,2,3,4,5]: + if vacation: + return '10:00' + return '7:00' + else: + if vacation: + return 'off' + return '10:00' print(alarm_clock(1, False)) print(alarm_clock(5, False)) diff --git a/logic-1/caught_speeding.py b/logic-1/caught_speeding.py index 3d1c566..f8d874f 100644 --- a/logic-1/caught_speeding.py +++ b/logic-1/caught_speeding.py @@ -2,7 +2,20 @@ def caught_speeding(speed, is_birthday): """ You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases. """ - pass + if not is_birthday: + if speed <= 60: + return 0 + elif speed <= 80: + return 1 + else: + return 2 + else: + if speed <= 65: + return 0 + elif speed <= 85: + return 1 + else: + return 2 print(caught_speeding(60, False)) print(caught_speeding(65, False)) diff --git a/logic-1/date_fashion.py b/logic-1/date_fashion.py index 4e618a0..22e5e2b 100644 --- a/logic-1/date_fashion.py +++ b/logic-1/date_fashion.py @@ -2,7 +2,12 @@ def date_fashion(you, date): """ You and your date are trying to get a table at a restaurant. The parameter "you" is the stylishness of your clothes, in the range 0..10, and "date" is the stylishness of your date's clothes. The result getting the table is encoded as an int value with 0=no, 1=maybe, 2=yes. If either of you is very stylish, 8 or more, then the result is 2 (yes). With the exception that if either of you has style of 2 or less, then the result is 0 (no). Otherwise the result is 1 (maybe). """ - pass + if you <=2 or date <= 2: + return 0 + elif you >= 8 or date >= 8: + return 2 + else: + return 1 print(date_fashion(5, 10)) print(date_fashion(5, 2)) diff --git a/logic-1/in1to10.py b/logic-1/in1to10.py index 65e3452..549b1a1 100644 --- a/logic-1/in1to10.py +++ b/logic-1/in1to10.py @@ -2,7 +2,7 @@ def in1to10(n, outside_mode): """ Given a number n, return True if n is in the range 1..10, inclusive. Unless outside_mode is True, in which case return True if the number is less or equal to 1, or greater or equal to 10. """ - pass + return (n in range(1, 11)) is not outside_mode or (n not in range(2, 10)) is outside_mode print(in1to10(5, False)) print(in1to10(11, False)) diff --git a/logic-1/love6.py b/logic-1/love6.py index c705954..e4cd553 100644 --- a/logic-1/love6.py +++ b/logic-1/love6.py @@ -2,7 +2,7 @@ def love6(a, b): """ The number 6 is a truly great number. Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6. Note: the function abs(num) computes the absolute value of a number. """ - pass + return a == 6 or b == 6 or a+b == 6 or abs(a-b) == 6 print(love6(6, 4)) print(love6(4, 5)) diff --git a/logic-1/near_ten.py b/logic-1/near_ten.py index 852a382..2bb427a 100644 --- a/logic-1/near_ten.py +++ b/logic-1/near_ten.py @@ -2,7 +2,7 @@ def near_ten(num): """ Given a non-negative number "num", return True if num is within 2 of a multiple of 10. Note: (a % b) is the remainder of dividing a by b, so (7 % 5) is 2. See also: Introduction to Mod """ - pass + return num%10 <= 2 or num%10 >= 8 print(near_ten(12)) print(near_ten(17)) diff --git a/logic-1/sorta_sum.py b/logic-1/sorta_sum.py index aed9eea..96e42d5 100644 --- a/logic-1/sorta_sum.py +++ b/logic-1/sorta_sum.py @@ -2,7 +2,10 @@ def sorta_sum(a, b): """ Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20. """ - pass + if a + b in range(10, 20): + return 20 + else: + return a + b print(sorta_sum(3, 4)) print(sorta_sum(9, 4)) diff --git a/logic-1/squirrel_play.py b/logic-1/squirrel_play.py index 2d3af38..bab3d4b 100644 --- a/logic-1/squirrel_play.py +++ b/logic-1/squirrel_play.py @@ -2,7 +2,7 @@ def squirrel_play(temp, is_summer): """ The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a boolean is_summer, return True if the squirrels play and False otherwise. """ - pass + return temp in range (60, 91) or ((temp in range(60, 101)) and is_summer) print(squirrel_play(70, False)) print(squirrel_play(95, False)) diff --git a/logic-2/close_far.py b/logic-2/close_far.py index 2542ff7..3a9a0a4 100644 --- a/logic-2/close_far.py +++ b/logic-2/close_far.py @@ -2,7 +2,7 @@ def close_far(a, b, c): """ Given three ints, a b c, return True if one of b or c is "close" (differing from a by at most 1), while the other is "far", differing from both other values by 2 or more. Note: abs(num) computes the absolute value of a number. """ - pass + return (abs(a - b) <= 1 and abs(a - c) >= 2 or abs(a - c) <= 1 and abs(a - b) >= 2) and abs(b - c) >= 2 print(close_far(1, 2, 10)) print(close_far(1, 2, 3)) diff --git a/logic-2/lucky_sum.py b/logic-2/lucky_sum.py index 61c8061..080472c 100644 --- a/logic-2/lucky_sum.py +++ b/logic-2/lucky_sum.py @@ -2,7 +2,12 @@ def lucky_sum(a, b, c): """ Given 3 int values, a b c, return their sum. However, if one of the values is 13 then it does not count towards the sum and values to its right do not count. So for example, if b is 13, then both b and c do not count. """ - pass + val = 0 + for num in [a, b, c]: + if num == 13: + break + val += num + return val print(lucky_sum(1, 2, 3)) print(lucky_sum(1, 2, 13)) diff --git a/logic-2/make_bricks.py b/logic-2/make_bricks.py index c4e199e..88295d8 100644 --- a/logic-2/make_bricks.py +++ b/logic-2/make_bricks.py @@ -2,7 +2,7 @@ def make_bricks(small, big, goal): """ We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks. This is a little harder than it looks and can be done without any loops. See also: Introduction to MakeBricks """ - pass + return small*1 + big*5 >= goal and goal%5 <= small print(make_bricks(3, 1, 8)) print(make_bricks(3, 1, 9)) diff --git a/logic-2/make_chocolate.py b/logic-2/make_chocolate.py index 40b3bdd..17b2b90 100644 --- a/logic-2/make_chocolate.py +++ b/logic-2/make_chocolate.py @@ -2,7 +2,13 @@ def make_chocolate(small, big, goal): """ We want make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Return the number of small bars to use, assuming we always use big bars before small bars. Return -1 if it can't be done. """ - pass + if small*1 + big*5 >= goal and goal%5 <= small: + if goal//5 >= big: + return goal - 9//5 * big * 5 + else: + return goal%5 + else: + return -1 print(make_chocolate(4, 1, 9)) print(make_chocolate(4, 1, 10)) diff --git a/logic-2/no_teen_sum.py b/logic-2/no_teen_sum.py index a746ed9..e9f779d 100644 --- a/logic-2/no_teen_sum.py +++ b/logic-2/no_teen_sum.py @@ -2,7 +2,13 @@ def no_teen_sum(a, b, c): """ Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "def fix_teen(n):"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main no_teen_sum(). """ - pass + return fix_teen(a) + fix_teen(b) + fix_teen(c) + +def fix_teen(n): + if n in range(13, 20) and (n != 15 and n !=16): + return 0 + else: + return n print(no_teen_sum(1, 2, 3)) print(no_teen_sum(2, 13, 1)) diff --git a/logic-2/round_sum.py b/logic-2/round_sum.py index 528c52d..0d6f3d2 100644 --- a/logic-2/round_sum.py +++ b/logic-2/round_sum.py @@ -2,7 +2,13 @@ def round_sum(a, b, c): """ For this problem, we'll round an int value up to the next multiple of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20. Alternately, round down to the previous multiple of 10 if its rightmost digit is less than 5, so 12 rounds down to 10. Given 3 ints, a b c, return the sum of their rounded values. To avoid code repetition, write a separate helper "def round10(num):" and call it 3 times. Write the helper entirely below and at the same indent level as round_sum(). """ - pass + return round10(a) + round10(b) + round10(c) + +def round10(num): + if num%10 >= 5: + return num + 10 - num%10 + else: + return num - num%10 print(round_sum(16, 17, 18)) print(round_sum(12, 13, 14)) diff --git a/string-2/cat_dog.py b/string-2/cat_dog.py index 6bc1289..93d6998 100644 --- a/string-2/cat_dog.py +++ b/string-2/cat_dog.py @@ -2,7 +2,7 @@ def cat_dog(str): """ Return True if the string "cat" and "dog" appear the same number of times in the given string. """ - pass + return str.count('dog') == str.count('cat') print(cat_dog('catdog')) print(cat_dog('catcat')) diff --git a/string-2/count_code.py b/string-2/count_code.py index de99db8..c1a55e1 100644 --- a/string-2/count_code.py +++ b/string-2/count_code.py @@ -2,7 +2,11 @@ def count_code(str): """ Return the number of times that the string "code" appears anywhere in the given string, except we'll accept any letter for the 'd', so "cope" and "cooe" count. """ - pass + count = 0 + for i in range(0, len(str) - 3): + if str[i] == "c" and str[i+1] == "o" and str[i+3] == "e": + count += 1 + return count print(count_code('aaacodebbb')) print(count_code('codexxcode')) diff --git a/string-2/count_hi.py b/string-2/count_hi.py index f0afce7..d5a40aa 100644 --- a/string-2/count_hi.py +++ b/string-2/count_hi.py @@ -2,7 +2,7 @@ def count_hi(str): """ Return the number of times that the string "hi" appears anywhere in the given string. """ - pass + return str.count('hi') print(count_hi('abc hi ho')) print(count_hi('ABChi hi')) diff --git a/string-2/end_other.py b/string-2/end_other.py index 37e32b0..34b8128 100644 --- a/string-2/end_other.py +++ b/string-2/end_other.py @@ -2,7 +2,7 @@ def end_other(a, b): """ Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: s.lower() returns the lowercase version of a string. """ - pass + return b.lower() == a.lower()[-len(b):] or a.lower() == b.lower()[-len(a):] print(end_other('Hiabc', 'abc')) print(end_other('AbC', 'HiaBc')) diff --git a/string-2/xyz_there.py b/string-2/xyz_there.py index dbb040f..d4b7ba3 100644 --- a/string-2/xyz_there.py +++ b/string-2/xyz_there.py @@ -2,7 +2,12 @@ def xyz_there(str): """ Return True if the given string contains an appearance of "xyz" where the xyz is not directly preceeded by a period (.). So "xxyz" counts but "x.xyz" does not. """ - pass + if str[:3] == 'xyz': + return True + for i in range(len(str) - 3): + if str[i] != '.' and str[i+1:i+4] == 'xyz': + return True + return False print(xyz_there('abcxyz')) print(xyz_there('abc.xyz'))