From 8562fd00c20f3dc6ddc54255e14c064d54b1f8f8 Mon Sep 17 00:00:00 2001 From: RizingTide Date: Fri, 9 Dec 2022 15:51:35 -0500 Subject: [PATCH 1/7] Finished Problem 1 Iterated through the list, if an integer was greater than 0 it is positive Found the index position that needed to be changed and set it to a new value --- 12_09_practice.py | 49 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/12_09_practice.py b/12_09_practice.py index 7914563..6165579 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -1,29 +1,56 @@ -#Biggie Size - Given a list, write a function that changes all positive numbers in the list to "big". Example: make_it_big([-1, 3, 5, -5]) returns that same list, #changed to [-1, "big", "big", -5]. +#Biggie Size - Given a list, write a function that changes all positive numbers in the list to "big". +#Example: make_it_big([-1, 3, 5, -5]) returns that same list, #changed to [-1, "big", "big", -5]. +def make_positive_big(numbers): + for integer in numbers: + if integer > 0: + position=numbers.index(integer) + numbers[position]="big" -#Count Positives - Given a list of numbers, create a function to replace last value with number of positive values. Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it. (Note that zero is not considered to be a positive number). +make_positive_big([6,10,4,-6,-8]) -#SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. For example sum_total([1,2,3,4]) should return 10 +#Count Positives - Given a list of numbers, create a function to replace last value with number of positive values. +# Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it. (Note that zero is not considered to be a positive number). -#Average - Create a function that takes a list as an argument and returns the average of all the values in the list. For example multiples([1,2,3,4]) should return #2.5 -#Length - Create a function that takes a list as an argument and returns the length of the list. For example length([1,2,3,4]) should return 4 +#SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. +#For example sum_total([1,2,3,4]) should return 10 + + +#Average - Create a function that takes a list as an argument and returns the average of all the values in the list. +#For example multiples([1,2,3,4]) should return #2.5 + + +#Length - Create a function that takes a list as an argument and returns the length of the list. +#For example length([1,2,3,4]) should return 4 + + +#Minimum - Create a function that takes a list as an argument and returns the minimum value in the list. +#If the passed list is empty, have the function return false. #For example minimum([1,2,3,4]) should return 1; minimum([-1,-2,-3]) should return -3. + + +#Maximum - Create a function that takes a list as an argument and returns the maximum value in the list. +#If the passed list is empty, have the function return false. #For example maximum([1,2,3,4]) should return 4; maximum([-1,-2,-3]) should return -1. -#Minimum - Create a function that takes a list as an argument and returns the minimum value in the list. If the passed list is empty, have the function return false. #For example minimum([1,2,3,4]) should return 1; minimum([-1,-2,-3]) should return -3. -# -#Maximum - Create a function that takes a list as an argument and returns the maximum value in the list. If the passed list is empty, have the function return false. #For example maximum([1,2,3,4]) should return 4; maximum([-1,-2,-3]) should return -1. #Ultimateaalyze - Create a function that takes a list as an argument and returns a dictionary that has the sumTotal, average, minimum, maximum ad length of the list. -#ReverseList - Create a function that takes a list as a argument and return a list in a reversed order. Do this without creating a empty temporary list. For example #reverse([1,2,3,4]) should return [4,3,2,1]. This challenge is known to appear during basic technical interviews. -#Ispalindrome- Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if the reverse of the string is the same as string. For example, “radar” is a palindrome, but “radix” is not a palindrome. +#ReverseList - Create a function that takes a list as a argument and return a list in a reversed order. Do this without creating a empty temporary list. +# For example #reverse([1,2,3,4]) should return [4,3,2,1]. This challenge is known to appear during basic technical interviews. + + +#Ispalindrome- Given a string, write a python function to check if it is palindrome or not. +#A string is said to be palindrome if the reverse of the string is the same as string. For example, “radar” is a palindrome, but “radix” is not a palindrome. + #Fizzbuzz- Create a function that will print numbers from 1 to 100, with certain exceptions: #If the number is a multiple of 3, print “Fizz” instead of the number. #If the number is a multiple of 5, print “Buzz” instead of the number. #If the number is a multiple of 3 and 5, print “FizzBuzz” instead of the number. -#Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is, + +#Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, +#such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is, #F(0) = 0, F(1) = 1 #F(n) = F(n - 1) + F(n - 2), for n > 1. #Create a function that accepts any number and will create a sequence based on the fibonacci sequence. \ No newline at end of file From ee4ad7d79ba036f7ee8db3a83c65796f67ad6cad Mon Sep 17 00:00:00 2001 From: RizingTide Date: Fri, 9 Dec 2022 16:00:58 -0500 Subject: [PATCH 2/7] Problem 2 Finished Iterated through the list, if a number is greater than 0 updated the count variable, and then set the last index to the count variable --- 12_09_practice.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/12_09_practice.py b/12_09_practice.py index 6165579..86c7e9b 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -1,16 +1,23 @@ #Biggie Size - Given a list, write a function that changes all positive numbers in the list to "big". #Example: make_it_big([-1, 3, 5, -5]) returns that same list, #changed to [-1, "big", "big", -5]. + def make_positive_big(numbers): for integer in numbers: if integer > 0: position=numbers.index(integer) numbers[position]="big" - -make_positive_big([6,10,4,-6,-8]) + print(numbers) #Count Positives - Given a list of numbers, create a function to replace last value with number of positive values. # Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it. (Note that zero is not considered to be a positive number). +def replace_last_pos_count(numbers): + positive_count = 0 + for integers in numbers: + if integers > 0: + positive_count+=1 + numbers[-1] = positive_count + print(numbers) #SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. #For example sum_total([1,2,3,4]) should return 10 From 2efd69e0e3b8e02bed4334fc56247c621b8e12d7 Mon Sep 17 00:00:00 2001 From: RizingTide Date: Fri, 9 Dec 2022 16:39:31 -0500 Subject: [PATCH 3/7] Finished Problem 3 --- 12_09_practice.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/12_09_practice.py b/12_09_practice.py index 86c7e9b..9587b73 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -6,7 +6,7 @@ def make_positive_big(numbers): if integer > 0: position=numbers.index(integer) numbers[position]="big" - print(numbers) + return(numbers) #Count Positives - Given a list of numbers, create a function to replace last value with number of positive values. # Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it. (Note that zero is not considered to be a positive number). @@ -17,11 +17,13 @@ def replace_last_pos_count(numbers): if integers > 0: positive_count+=1 numbers[-1] = positive_count - print(numbers) + return(numbers) #SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. #For example sum_total([1,2,3,4]) should return 10 +def sum_values(numbers): + return(sum(numbers)) #Average - Create a function that takes a list as an argument and returns the average of all the values in the list. #For example multiples([1,2,3,4]) should return #2.5 From 0dc6d44cad2ffdda85342c7f1abcab3e63cd0ff1 Mon Sep 17 00:00:00 2001 From: RizingTide Date: Sat, 10 Dec 2022 00:43:33 -0500 Subject: [PATCH 4/7] Update 12_09_practice.py --- 12_09_practice.py | 118 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 3 deletions(-) diff --git a/12_09_practice.py b/12_09_practice.py index 9587b73..f35b5ac 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -19,44 +19,156 @@ def replace_last_pos_count(numbers): numbers[-1] = positive_count return(numbers) -#SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. +#SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. #For example sum_total([1,2,3,4]) should return 10 def sum_values(numbers): return(sum(numbers)) +def sum_values_2(numbers): + count=0 + for i in numbers: + count+=i + return count + #Average - Create a function that takes a list as an argument and returns the average of all the values in the list. #For example multiples([1,2,3,4]) should return #2.5 +def avg_values(numbers): + average=sum(numbers)/len(numbers) + return average + +def avg_values_2(numbers): + count=0 + for i in numbers: + count+=i + average = count/len(numbers) + return average #Length - Create a function that takes a list as an argument and returns the length of the list. #For example length([1,2,3,4]) should return 4 +def length(numbers): + return len(numbers) + +def length_2(numbers): + count=0 + for i in numbers: + count+=1 + return count #Minimum - Create a function that takes a list as an argument and returns the minimum value in the list. #If the passed list is empty, have the function return false. #For example minimum([1,2,3,4]) should return 1; minimum([-1,-2,-3]) should return -3. +def minimum_1(numbers): + empty_list= [] + if len(numbers) == len(empty_list): + return False + else: + return min(numbers) + +def minimum_2(numbers): + empty_list= [] + if len(numbers) == len(empty_list): + return False + else: + small=numbers[0] + for i in numbers: + if i < small: + small=i + return small + +''' +# I was curious to see if I could make a function that accounts for an edge case, of a list is provided with numbers that are in strings +def minimum_3(numbers): + empty_list= [] + if len(numbers) == len(empty_list): + return False + else: + for i in numbers: + new_list = [] + if type(i) == str and i.isalpha() is not True: + new_list.append(float(i)) + else: + new_list.append(i) + return min(new_list) + return min(numbers) +''' #Maximum - Create a function that takes a list as an argument and returns the maximum value in the list. #If the passed list is empty, have the function return false. #For example maximum([1,2,3,4]) should return 4; maximum([-1,-2,-3]) should return -1. +def maxium_1(numbers): + empty_list= [] + if len(numbers) == len(empty_list): + return False + else: + return max(numbers) + +def maximum_2(numbers): + empty_list= [] + if len(numbers) == len(empty_list): + return False + else: + big=numbers[0] + for i in numbers: + if i > big: + big=i + return big #Ultimateaalyze - Create a function that takes a list as an argument and returns a dictionary that has the sumTotal, average, minimum, maximum ad length of the list. + #ReverseList - Create a function that takes a list as a argument and return a list in a reversed order. Do this without creating a empty temporary list. # For example #reverse([1,2,3,4]) should return [4,3,2,1]. This challenge is known to appear during basic technical interviews. - +''' +# Why doesn't this work? +def reversal_2(numbers): + count=0 + for i in range(0,len(numbers)): + backwards=numbers[(-1+count)] + count-=1 + numbers[i]=backwards + return numbers +''' +def reversal(numbers): + return numbers[::-1] #Ispalindrome- Given a string, write a python function to check if it is palindrome or not. #A string is said to be palindrome if the reverse of the string is the same as string. For example, “radar” is a palindrome, but “radix” is not a palindrome. - +def Is_palindrome_1(word): + if word == word[::-1]: + return "Is a Palindrome" + else: + return "Is not a Palindrome" + +def Is_palindrome_2(word): + new_word="" + for i in range(1, len(word)+1): + new_word+=word[-i] + if word == new_word: + return "Is a Palindrome" + else: + return "Is not a Palindrome" #Fizzbuzz- Create a function that will print numbers from 1 to 100, with certain exceptions: #If the number is a multiple of 3, print “Fizz” instead of the number. #If the number is a multiple of 5, print “Buzz” instead of the number. #If the number is a multiple of 3 and 5, print “FizzBuzz” instead of the number. +def Fizzbuzz(): + for i in range(1,101): + if i % 15 == 0: + print("FizzBuzz") + else: + if i % 3 ==0: + print("Fizz") + elif i % 5 ==0: + print("Buzz") + else: + print(i) +Fizzbuzz() #Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, #such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is, From 3b11ebc9f9c70d17cecb30ba6ec3effe7de5a054 Mon Sep 17 00:00:00 2001 From: RizingTide Date: Sat, 10 Dec 2022 15:57:26 -0500 Subject: [PATCH 5/7] Update 12_09_practice.py --- 12_09_practice.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/12_09_practice.py b/12_09_practice.py index f35b5ac..c4a7b7c 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -172,6 +172,21 @@ def Fizzbuzz(): #Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, #such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is, - #F(0) = 0, F(1) = 1 - #F(n) = F(n - 1) + F(n - 2), for n > 1. - #Create a function that accepts any number and will create a sequence based on the fibonacci sequence. \ No newline at end of file +#F(0) = 0, F(1) = 1 +#F(n) = F(n - 1) + F(n - 2), for n > 1. +#Create a function that accepts any number and will create a sequence based on the fibonacci sequence. + +def Fibonacci(number): + start=[0,1] + count=0 + while count+22: + return start + elif number==0: + return start[0] + elif number==1: + return start[1] + +print(Fibonacci(9)) From c45d5f3a22ea912fff90a99a7e7db47e1df8fe51 Mon Sep 17 00:00:00 2001 From: RizingTide Date: Sat, 10 Dec 2022 16:26:04 -0500 Subject: [PATCH 6/7] Update 12_09_practice.py --- 12_09_practice.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/12_09_practice.py b/12_09_practice.py index c4a7b7c..89ed728 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -118,7 +118,23 @@ def maximum_2(numbers): #Ultimateaalyze - Create a function that takes a list as an argument and returns a dictionary that has the sumTotal, average, minimum, maximum ad length of the list. - +def create_dict_analyze(numbers): + new_dict = { } + count = 0 + small = numbers[0] + big = numbers[0] + for i in numbers: + count+=i + if i < small: + small = i + if i > big: + big = i + new_dict["sumTotal"] = count + new_dict["average"] = count/len(numbers) + new_dict["minimum"] = small + new_dict["maxiumum"] = big + new_dict["length"] = len(numbers) + return new_dict #ReverseList - Create a function that takes a list as a argument and return a list in a reversed order. Do this without creating a empty temporary list. # For example #reverse([1,2,3,4]) should return [4,3,2,1]. This challenge is known to appear during basic technical interviews. @@ -187,6 +203,4 @@ def Fibonacci(number): elif number==0: return start[0] elif number==1: - return start[1] - -print(Fibonacci(9)) + return start[1] \ No newline at end of file From 3b506bf34f7f2e4935dc9952de62034c29c54ebd Mon Sep 17 00:00:00 2001 From: RizingTide Date: Mon, 12 Dec 2022 15:50:41 -0500 Subject: [PATCH 7/7] Commit --- Lambda_practice.py | 11 +++++++++++ practice.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Lambda_practice.py create mode 100644 practice.py diff --git a/Lambda_practice.py b/Lambda_practice.py new file mode 100644 index 0000000..6bfb4c3 --- /dev/null +++ b/Lambda_practice.py @@ -0,0 +1,11 @@ +# Consider the list: + +prog_lang = [('Python', 3.8), ('Java', 13), ('JavaScript', 2019), ('Scala', 2.13)] + +# 1. Sort the list by each language's version in ascending order. +sort_list = +# 2. Sort the list by the length of the name of each language in descending order. + +# 3. Filter the list so that it only contains languages with 'a' in it. + +# 4. Filter the list so that it only contains languages whose version is in integer form. \ No newline at end of file diff --git a/practice.py b/practice.py new file mode 100644 index 0000000..08fc216 --- /dev/null +++ b/practice.py @@ -0,0 +1,43 @@ +prime=[] + +for i in range(1,51): + for j in range(2,i): + if i%j == 0: + break + else: + prime.append(i) +print(prime) + +prime=[i] + +prime=[] +for i in range(2, 51): + if i == 2 or i == 3 or i == 5 or i == 7: + prime.append(i) + if i%2==0 or i%3==0 or i%5==0 or i%7==0: + pass + else: + prime.append(i) +print(prime) + +letters=["a", "b", "c", "d"] +dict={} +count=1 +for i in letters: + dict[count]=i + +add_num={} +for num in range(1,11): + add_num[num]= num+num + +print(add_num) + +# {key: value for loop } +add_num2={num: num+num for num in range(1,11)} +print(add_num2) + + + + +list=["FizzBuzz" if num % 15 == 0 else "Fizz" if num % 3 == 0 else "Buzz" if num % 5 == 0 else num for num in range(1,101)] +print(list)