From 7eb58662fa4497c9118bcbf47485956b61b1a789 Mon Sep 17 00:00:00 2001 From: hnaitlimam Date: Sun, 12 Sep 2021 13:19:29 +0100 Subject: [PATCH 1/4] Added solution for day1 task1 --- day1/solutions/task1/README.md | 4 ++++ day1/solutions/task1/solution.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 day1/solutions/task1/README.md create mode 100644 day1/solutions/task1/solution.py diff --git a/day1/solutions/task1/README.md b/day1/solutions/task1/README.md new file mode 100644 index 0000000..f5483ad --- /dev/null +++ b/day1/solutions/task1/README.md @@ -0,0 +1,4 @@ +# This is the solution for day 1 task 1 + +# The Task 1: Learn how you can create a string, an integer and an array. +# Write a program to initialize string, int variable and use them. \ No newline at end of file diff --git a/day1/solutions/task1/solution.py b/day1/solutions/task1/solution.py new file mode 100644 index 0000000..036e8cb --- /dev/null +++ b/day1/solutions/task1/solution.py @@ -0,0 +1,33 @@ +# Solution for day1 task1 + +# Initializing a string +course = "Learn python with LetUsDevOps" +print("length of string course: ", len(course)) # length of course +print("first char: ", course[0], "last char :", course[-1]) # length of course +# substring so OP but python allocate new memory +print("substring a string: ", course[0:3]) +print("Checking if a string starts with a specific first letter: ", course.startswith("p")) + +# formating strings +first = "Hamdi" +last = "Nait Limam" +full = f"{first} {last}" +print("Concating string with formated string: ", full) + +# Initializing an integer +count = 5 +x = y = 1 +x, y = 2, 1 +print("typeOf count is :", type(count)) # typeOf() +print(f"sum of two integers :{x+y}\nsubsctraction of two integers: {x-y}\nmultiplication of two integers: {x*y}") + +# Initializing an Array +# Arrays are used to store multiple values in one single variable containing homogeneous elements i.e. belonging to the same data type. +t = [3, 1, 2, 3] +print("Printing the array: ", t) +print("length of the array is :", len(t)) +print("Printing ID of the array t before: ", id(t)) +t.append(4) # pushing another value into the array +t.sort() +print("Printing ID of the array t after: ", id(t)) +print("Printing the array after the changes: ", t) \ No newline at end of file From a0bc6bd3e84e28f00c9f2f80b63ddc93bc1efc4e Mon Sep 17 00:00:00 2001 From: hnaitlimam Date: Sun, 12 Sep 2021 13:54:55 +0100 Subject: [PATCH 2/4] Fixed a typo in README file --- day1/solutions/task1/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/day1/solutions/task1/README.md b/day1/solutions/task1/README.md index f5483ad..c0e47a2 100644 --- a/day1/solutions/task1/README.md +++ b/day1/solutions/task1/README.md @@ -1,4 +1,4 @@ # This is the solution for day 1 task 1 -# The Task 1: Learn how you can create a string, an integer and an array. -# Write a program to initialize string, int variable and use them. \ No newline at end of file +The Task 1: Learn how you can create a string, an integer and an array. +Write a program to initialize string, int variable and use them. From 22a6cf85dc0cc93e5c5285388e0329a52377466b Mon Sep 17 00:00:00 2001 From: hnaitlimam Date: Sun, 12 Sep 2021 13:55:45 +0100 Subject: [PATCH 3/4] Added solution of day1 task3 --- day1/solutions/task2/README.md | 5 ++++ day1/solutions/task2/solution.py | 23 +++++++++++++++++ day1/solutions/task3/README.md | 5 ++++ day1/solutions/task3/solution.py | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 day1/solutions/task2/README.md create mode 100644 day1/solutions/task2/solution.py create mode 100644 day1/solutions/task3/README.md create mode 100644 day1/solutions/task3/solution.py diff --git a/day1/solutions/task2/README.md b/day1/solutions/task2/README.md new file mode 100644 index 0000000..8dcb503 --- /dev/null +++ b/day1/solutions/task2/README.md @@ -0,0 +1,5 @@ +# This is the solution of day 1 task 2 + +Learn how you can loop through a list of elements. +- Try to create an array of element and loop over it. +- Practice: Try to generate table to 2,3,4 and 5 diff --git a/day1/solutions/task2/solution.py b/day1/solutions/task2/solution.py new file mode 100644 index 0000000..421f926 --- /dev/null +++ b/day1/solutions/task2/solution.py @@ -0,0 +1,23 @@ +# Solution for day1 task1 + +# Simple iteration over a loop +list = [1,2,3,4,5,6,7,8,9] +print("Print the list with simple iteration:") +for i in list: + print(i, end=" ") + +# The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. +print(" ") +print("Printing range(5) loop:") +for x in range(5): + print(x, end=" ") + +print(" ") +print("Printing range(2,6) loop:") +for x in range(2,6): + print(x, end=" ") + +print(" ") +print("Printing range(0,10,2) loop:") +for x in range(0,10,2): + print(x, end=" ") \ No newline at end of file diff --git a/day1/solutions/task3/README.md b/day1/solutions/task3/README.md new file mode 100644 index 0000000..8bf77aa --- /dev/null +++ b/day1/solutions/task3/README.md @@ -0,0 +1,5 @@ +# This is the solution of day 1 task 3 + +Task 3: WAP to generate odd and even numbers with for and while loops. +- Two programs to generate even and then odd. +- You can also try solving fizzbuzz problem as an extended goal. \ No newline at end of file diff --git a/day1/solutions/task3/solution.py b/day1/solutions/task3/solution.py new file mode 100644 index 0000000..1ecf7a3 --- /dev/null +++ b/day1/solutions/task3/solution.py @@ -0,0 +1,42 @@ +# Solution of day1 task3 + +# Generating even and odd numbers with for loop +print('Generating Odd and Even numbers exerice with For loop!') +even=[] +odd=[] +for i in range(1,11): + if(i%2==0): + even.append(i) + else: + odd.append(i) + +print("The even numbers are: ", even) +print("The odd numbers are: ", odd) + +# Generating even and odd numbers with while loop +print('Generating Odd and Even numbers exerice with while loop!') +even=[] +odd=[] +i = 1 +while i <= 11: + if(i%2==0): + even.append(i) + else: + odd.append(i) + i += 1 + +print("The even numbers are: ", even) +print("The odd numbers are: ", odd) + +# Fizz Buzz Exercice +print('Welcome to Fizz Buzz exerice!') +for i in range(1,101): + if i % 3 ==0 and i % 5 == 0: + print(i, "FizzBuzz") + elif i % 3 == 0: + print(i, "Fizz") + elif i % 5 == 0: + print(i, "Buzz") + else: + print(i) + From 864dba1d8b569fc9ac43b4501c10feed4d545994 Mon Sep 17 00:00:00 2001 From: hnaitlimam Date: Mon, 13 Sep 2021 11:33:56 +0100 Subject: [PATCH 4/4] Removed solution of day1 task1 and task2 --- day1/solutions/task1/README.md | 4 ---- day1/solutions/task1/solution.py | 33 -------------------------------- day1/solutions/task2/README.md | 5 ----- day1/solutions/task2/solution.py | 23 ---------------------- 4 files changed, 65 deletions(-) delete mode 100644 day1/solutions/task1/README.md delete mode 100644 day1/solutions/task1/solution.py delete mode 100644 day1/solutions/task2/README.md delete mode 100644 day1/solutions/task2/solution.py diff --git a/day1/solutions/task1/README.md b/day1/solutions/task1/README.md deleted file mode 100644 index c0e47a2..0000000 --- a/day1/solutions/task1/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# This is the solution for day 1 task 1 - -The Task 1: Learn how you can create a string, an integer and an array. -Write a program to initialize string, int variable and use them. diff --git a/day1/solutions/task1/solution.py b/day1/solutions/task1/solution.py deleted file mode 100644 index 036e8cb..0000000 --- a/day1/solutions/task1/solution.py +++ /dev/null @@ -1,33 +0,0 @@ -# Solution for day1 task1 - -# Initializing a string -course = "Learn python with LetUsDevOps" -print("length of string course: ", len(course)) # length of course -print("first char: ", course[0], "last char :", course[-1]) # length of course -# substring so OP but python allocate new memory -print("substring a string: ", course[0:3]) -print("Checking if a string starts with a specific first letter: ", course.startswith("p")) - -# formating strings -first = "Hamdi" -last = "Nait Limam" -full = f"{first} {last}" -print("Concating string with formated string: ", full) - -# Initializing an integer -count = 5 -x = y = 1 -x, y = 2, 1 -print("typeOf count is :", type(count)) # typeOf() -print(f"sum of two integers :{x+y}\nsubsctraction of two integers: {x-y}\nmultiplication of two integers: {x*y}") - -# Initializing an Array -# Arrays are used to store multiple values in one single variable containing homogeneous elements i.e. belonging to the same data type. -t = [3, 1, 2, 3] -print("Printing the array: ", t) -print("length of the array is :", len(t)) -print("Printing ID of the array t before: ", id(t)) -t.append(4) # pushing another value into the array -t.sort() -print("Printing ID of the array t after: ", id(t)) -print("Printing the array after the changes: ", t) \ No newline at end of file diff --git a/day1/solutions/task2/README.md b/day1/solutions/task2/README.md deleted file mode 100644 index 8dcb503..0000000 --- a/day1/solutions/task2/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# This is the solution of day 1 task 2 - -Learn how you can loop through a list of elements. -- Try to create an array of element and loop over it. -- Practice: Try to generate table to 2,3,4 and 5 diff --git a/day1/solutions/task2/solution.py b/day1/solutions/task2/solution.py deleted file mode 100644 index 421f926..0000000 --- a/day1/solutions/task2/solution.py +++ /dev/null @@ -1,23 +0,0 @@ -# Solution for day1 task1 - -# Simple iteration over a loop -list = [1,2,3,4,5,6,7,8,9] -print("Print the list with simple iteration:") -for i in list: - print(i, end=" ") - -# The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. -print(" ") -print("Printing range(5) loop:") -for x in range(5): - print(x, end=" ") - -print(" ") -print("Printing range(2,6) loop:") -for x in range(2,6): - print(x, end=" ") - -print(" ") -print("Printing range(0,10,2) loop:") -for x in range(0,10,2): - print(x, end=" ") \ No newline at end of file