From c6e51d2f4718f58391e644adfd6a667c1fd43b44 Mon Sep 17 00:00:00 2001 From: brandonchin00 Date: Fri, 10 Dec 2021 03:59:53 -0500 Subject: [PATCH 1/4] update --- list-1/first_last6.py | 8 +++++++- list-2/count_evens.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/list-1/first_last6.py b/list-1/first_last6.py index 8e6cd71..95ccbba 100644 --- a/list-1/first_last6.py +++ b/list-1/first_last6.py @@ -1,6 +1,12 @@ def first_last6(nums): """Given an array of ints, return True if 6 appears as either the first or last element in the array. The array will be length 1 or more.""" - return nums[0] == 6 or nums[-1] == 6 + if nums[0] == 6: + return True + elif nums[-1] ==6: + return True + else: + return False + #return nums[0] == 6 or nums[-1] == 6 print(first_last6([1, 2, 6])) diff --git a/list-2/count_evens.py b/list-2/count_evens.py index dee910d..95c6fa4 100644 --- a/list-2/count_evens.py +++ b/list-2/count_evens.py @@ -3,6 +3,7 @@ def count_evens(nums): Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1. """ + evens = 0 for number in nums: if number % 2 == 0: From 61a8b1b4002167cb684c9cb9ecd77b9c9c1566b4 Mon Sep 17 00:00:00 2001 From: brandonchin00 Date: Fri, 10 Dec 2021 05:36:58 -0500 Subject: [PATCH 2/4] Update --- list-2/count_evens.py | 2 +- warmup-1/diff21.py | 16 ++++++++++++++++ warmup-1/missing_char.py | 8 ++++++++ warmup-1/monkey_trouble.py | 13 +++++++++++++ warmup-1/near_hundred.py | 14 ++++++++++++++ warmup-1/parrot_trouble.py | 14 ++++++++++++++ warmup-1/pos_neg.py | 24 ++++++++++++++++++++++++ warmup-1/sleep_in.py | 10 ---------- 8 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 warmup-1/diff21.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/parrot_trouble.py create mode 100644 warmup-1/pos_neg.py diff --git a/list-2/count_evens.py b/list-2/count_evens.py index 95c6fa4..a49d32e 100644 --- a/list-2/count_evens.py +++ b/list-2/count_evens.py @@ -3,7 +3,6 @@ def count_evens(nums): Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1. """ - evens = 0 for number in nums: if number % 2 == 0: @@ -11,6 +10,7 @@ def count_evens(nums): return evens + print(count_evens([2, 1, 2, 3, 4])) print(count_evens([2, 2, 0])) print(count_evens([1, 3, 5])) diff --git a/warmup-1/diff21.py b/warmup-1/diff21.py new file mode 100644 index 0000000..afca12d --- /dev/null +++ b/warmup-1/diff21.py @@ -0,0 +1,16 @@ +from math import sqrt +def diff21(number): + if number >= 21: + answer = number - 21 + answer = sqrt(answer ** 2) + print (answer) + elif number < 21: + answer = number - 21 + answer = 2 * (sqrt(answer ** 2)) + print (answer) + else: + print ("Error") + +diff21(19) +diff21(10) +diff21(21) diff --git a/warmup-1/missing_char.py b/warmup-1/missing_char.py new file mode 100644 index 0000000..ece3677 --- /dev/null +++ b/warmup-1/missing_char.py @@ -0,0 +1,8 @@ +def missing_char(word, num): + final_word = word.replace(word[num],"") + + print(final_word) + +missing_char('kitten', 1) +missing_char('kitten', 0) +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..0d30ed8 --- /dev/null +++ b/warmup-1/monkey_trouble.py @@ -0,0 +1,13 @@ +def monkey_trouble(input1, input2): + if input1 == input2: + print ("True") + else: + print ("False") + + + + + +monkey_trouble(True, True) +monkey_trouble(False, False) +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..736123b --- /dev/null +++ b/warmup-1/near_hundred.py @@ -0,0 +1,14 @@ +"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." + +def near_hundred(num): + if num in range(90, 110): + print ("True") + elif num in range(190, 210): + print ("True") + else: + print ("False") + + +near_hundred(93) +near_hundred(90) +near_hundred(89) \ 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..1632161 --- /dev/null +++ b/warmup-1/parrot_trouble.py @@ -0,0 +1,14 @@ +def parrot_trouble(input, num): + if input == True: + if num in range(20, 24): + print (True) + elif num in range(0, 7): + print (True) + else: + print (False) + else: + print (False) + +parrot_trouble(True, 6) +parrot_trouble(True, 7) +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..2359e99 --- /dev/null +++ b/warmup-1/pos_neg.py @@ -0,0 +1,24 @@ + +def pos_neg(num1, num2, input): + if input == False: + if num1 == -abs(num1): + if num2 == abs(num2): + print (True) + else: + print (False) + elif num1 == abs(num1): + if num2 == -abs(num2): + print (True) + else: + print (False) + elif input == True: + if num1 == -abs(num1) and num2 == -abs(num2): + print (True) + else: + print (False) + + +pos_neg(1, -1, False) +pos_neg(-1, 1, False) +pos_neg(-4, 5, True) + diff --git a/warmup-1/sleep_in.py b/warmup-1/sleep_in.py index 0f1fe64..e69de29 100644 --- a/warmup-1/sleep_in.py +++ b/warmup-1/sleep_in.py @@ -1,10 +0,0 @@ -def sleep_in(weekday, vacation): - """The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. - - Return True if we sleep in.""" - return not weekday or vacation - - -print(sleep_in(False, False)) -print(sleep_in(True, False)) -print(sleep_in(False, True)) From 229168e3dbb0be24f986d581af00a84418a9cb7b Mon Sep 17 00:00:00 2001 From: brandonchin00 Date: Fri, 10 Dec 2021 05:49:56 -0500 Subject: [PATCH 3/4] update --- warmup-1/front_back.py | 11 +++++++++++ warmup-1/missing_char.py | 1 - warmup-1/monkey_trouble.py | 2 -- warmup-1/pos_neg.py | 2 +- warmup-1/sleep_in.py | 9 +++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 warmup-1/front_back.py diff --git a/warmup-1/front_back.py b/warmup-1/front_back.py new file mode 100644 index 0000000..190775d --- /dev/null +++ b/warmup-1/front_back.py @@ -0,0 +1,11 @@ +def front_back(word): + word = list(word) + word = word[0] + word1 = word[-1] + final_word = word.replace(word[0], word[-1]) + final2_word = final_word.join(word1) + print (final_word) + +front_back('code') +front_back('a') +front_back('ab') \ No newline at end of file diff --git a/warmup-1/missing_char.py b/warmup-1/missing_char.py index ece3677..72dcb0a 100644 --- a/warmup-1/missing_char.py +++ b/warmup-1/missing_char.py @@ -1,6 +1,5 @@ def missing_char(word, num): final_word = word.replace(word[num],"") - print(final_word) missing_char('kitten', 1) diff --git a/warmup-1/monkey_trouble.py b/warmup-1/monkey_trouble.py index 0d30ed8..37bf96d 100644 --- a/warmup-1/monkey_trouble.py +++ b/warmup-1/monkey_trouble.py @@ -6,8 +6,6 @@ def monkey_trouble(input1, input2): - - monkey_trouble(True, True) monkey_trouble(False, False) monkey_trouble(True, False) \ No newline at end of file diff --git a/warmup-1/pos_neg.py b/warmup-1/pos_neg.py index 2359e99..f414524 100644 --- a/warmup-1/pos_neg.py +++ b/warmup-1/pos_neg.py @@ -20,5 +20,5 @@ def pos_neg(num1, num2, input): pos_neg(1, -1, False) pos_neg(-1, 1, False) -pos_neg(-4, 5, True) +pos_neg(-4, -5, True) diff --git a/warmup-1/sleep_in.py b/warmup-1/sleep_in.py index e69de29..46973f1 100644 --- a/warmup-1/sleep_in.py +++ b/warmup-1/sleep_in.py @@ -0,0 +1,9 @@ +def sleep_in(weekday, vacation): + """The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. + Return True if we sleep in.""" + return not weekday or vacation + + +print(sleep_in(False, False)) +print(sleep_in(True, False)) +print(sleep_in(False, True)) \ No newline at end of file From 8846e659cbbd4441779d9772645a3f9022e34fe3 Mon Sep 17 00:00:00 2001 From: brandonchin00 Date: Fri, 10 Dec 2021 20:41:38 -0500 Subject: [PATCH 4/4] update --- test.py | 7 +++++++ warmup-1/front.py | 6 ++++++ warmup-1/makes10.py | 11 +++++++++++ warmup-1/not_string.py | 10 ++++++++++ warmup-1/sum_double.py | 11 +++++++++++ warmup-2/array_front9.py | 11 +++++++++++ warmup-2/front_times.py | 8 ++++++++ warmup-2/last2.py | 0 warmup-2/string_splosion.py | 10 ++++++++++ 9 files changed, 74 insertions(+) create mode 100644 test.py create mode 100644 warmup-1/front.py create mode 100644 warmup-1/makes10.py create mode 100644 warmup-1/not_string.py create mode 100644 warmup-1/sum_double.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_splosion.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..5bd98e9 --- /dev/null +++ b/test.py @@ -0,0 +1,7 @@ +lst = [] +num = int(input("Enter the size of the array: ")) +print("Enter array elements: ") +for n in range(num): + numbers = int(input()) + lst.append(numbers) +print("Sum:", sum(lst)) diff --git a/warmup-1/front.py b/warmup-1/front.py new file mode 100644 index 0000000..6200502 --- /dev/null +++ b/warmup-1/front.py @@ -0,0 +1,6 @@ +def front3 (word): + print(f'{word[0]}{word[1]}{word[2]}{word[0]}{word[1]}{word[2]}{word[0]}{word[1]}{word[2]}') + +front3('Java') +front3('Chocolate') +front3('abc') \ No newline at end of file diff --git a/warmup-1/makes10.py b/warmup-1/makes10.py new file mode 100644 index 0000000..3940dd1 --- /dev/null +++ b/warmup-1/makes10.py @@ -0,0 +1,11 @@ +def makes10(num1, num2): + if num1 == 10 or num2 == 10: + print (True) + elif num1 + num2 == 10: + print (True) + else: + print (False) + +makes10(9, 10) +makes10(9, 9) +makes10(1, 9) \ 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..9555bd4 --- /dev/null +++ b/warmup-1/not_string.py @@ -0,0 +1,10 @@ +def not_string(word): + if 'not' in word: + print (word) + else: + print ('not ' + word) + + +not_string('candy') +not_string('x') +not_string('not bad') \ 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..697169c --- /dev/null +++ b/warmup-1/sum_double.py @@ -0,0 +1,11 @@ +def sum_double(num1, num2): + if num1 == num2: + final_value = (num1 + num2) * 2 + print (final_value) + else: + final_value = num1 + num2 + print (final_value) + +sum_double(1, 2) +sum_double(3, 2) +sum_double(2, 2) \ 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..1e14720 --- /dev/null +++ b/warmup-2/array_front9.py @@ -0,0 +1,11 @@ +def array_front9(array): + #total = sum(array[:4]) + #print (total) + if 9 in array[0:4]: + print (True) + else: + print (False) + +array_front9([1, 2, 9, 3, 4]) +array_front9([1, 2, 3, 4, 9]) +array_front9([1, 2, 3, 4, 5]) diff --git a/warmup-2/front_times.py b/warmup-2/front_times.py new file mode 100644 index 0000000..e09f832 --- /dev/null +++ b/warmup-2/front_times.py @@ -0,0 +1,8 @@ +def front_times(word, num): + new_word = word[0] + word[1] + word[2] + new_word = new_word * num + print(new_word) + +front_times('Chocolate', 2) +front_times('Chocolate', 3) +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..e69de29 diff --git a/warmup-2/string_splosion.py b/warmup-2/string_splosion.py new file mode 100644 index 0000000..4e5169e --- /dev/null +++ b/warmup-2/string_splosion.py @@ -0,0 +1,10 @@ +def string_splosion(word): + num = len(word) + final_word = "" + for i in range(num): + final_word = final_word + word[:i+1] + print (final_word) + +string_splosion('Code') +string_splosion('abc') +string_splosion('ab') \ No newline at end of file