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..a49d32e 100644 --- a/list-2/count_evens.py +++ b/list-2/count_evens.py @@ -10,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/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/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/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/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/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/missing_char.py b/warmup-1/missing_char.py new file mode 100644 index 0000000..72dcb0a --- /dev/null +++ b/warmup-1/missing_char.py @@ -0,0 +1,7 @@ +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..37bf96d --- /dev/null +++ b/warmup-1/monkey_trouble.py @@ -0,0 +1,11 @@ +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/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/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..f414524 --- /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..46973f1 100644 --- a/warmup-1/sleep_in.py +++ b/warmup-1/sleep_in.py @@ -1,10 +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)) +print(sleep_in(False, 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..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