From f1863493ecfa3ffa912a59806caa7ea15e06603c Mon Sep 17 00:00:00 2001 From: Ganome Date: Sun, 18 Apr 2021 21:39:05 +0000 Subject: [PATCH] added another exercise --- .../README.md | 0 .../helloworld.py | 0 .../README.md | 0 .../arithmetic.py | 0 .../exercise.py | 0 .../floating-point.py | 0 .../integers.py | 0 .../strings.py | 0 .../README.md | 0 .../example.py | 0 .../exercise.py | 0 .../README.md | 0 .../arithmetic.py | 0 .../exercise.py | 0 .../joining-strings.py | 0 .../README.md | 0 .../exercise.py | 0 .../string-formatting.py | 0 .../README.md | 0 .../exercise.py | 0 .../strings.py | 0 .../README.md | 0 .../Basics/chapter-07-conditionals/example.py | 62 +++++++++++++++++++ .../chapter-07-conditionals/exercise.py | 25 ++++++++ .../Basics/chapter-08-Loops/README.md | 20 ++++++ .../Basics/chapter-08-Loops/example.py | 50 +++++++++++++++ .../Basics/chapter-08-Loops/exercise.py | 18 ++++++ .../Basics/chapter-09-Functions/README.md | 5 ++ .../Basics/chapter-09-Functions/example.py | 38 ++++++++++++ .../Basics/chapter-09-Functions/exercise.py | 14 +++++ 30 files changed, 232 insertions(+) rename python/learnpython.org/Basics/{chapter-01 => chapter-01-helloWorld}/README.md (100%) rename python/learnpython.org/Basics/{chapter-01 => chapter-01-helloWorld}/helloworld.py (100%) rename python/learnpython.org/Basics/{chapter-02 => chapter-02-Variables}/README.md (100%) rename python/learnpython.org/Basics/{chapter-02 => chapter-02-Variables}/arithmetic.py (100%) rename python/learnpython.org/Basics/{chapter-02 => chapter-02-Variables}/exercise.py (100%) rename python/learnpython.org/Basics/{chapter-02 => chapter-02-Variables}/floating-point.py (100%) rename python/learnpython.org/Basics/{chapter-02 => chapter-02-Variables}/integers.py (100%) rename python/learnpython.org/Basics/{chapter-02 => chapter-02-Variables}/strings.py (100%) rename python/learnpython.org/Basics/{chapter-03 => chapter-03-Lists}/README.md (100%) rename python/learnpython.org/Basics/{chapter-03 => chapter-03-Lists}/example.py (100%) rename python/learnpython.org/Basics/{chapter-03 => chapter-03-Lists}/exercise.py (100%) rename python/learnpython.org/Basics/{chapter-04 => chapter-04-Mathematics}/README.md (100%) rename python/learnpython.org/Basics/{chapter-04 => chapter-04-Mathematics}/arithmetic.py (100%) rename python/learnpython.org/Basics/{chapter-04 => chapter-04-Mathematics}/exercise.py (100%) rename python/learnpython.org/Basics/{chapter-04 => chapter-04-Mathematics}/joining-strings.py (100%) rename python/learnpython.org/Basics/{chapter-05 => chapter-05-Strings}/README.md (100%) rename python/learnpython.org/Basics/{chapter-05 => chapter-05-Strings}/exercise.py (100%) rename python/learnpython.org/Basics/{chapter-05 => chapter-05-Strings}/string-formatting.py (100%) rename python/learnpython.org/Basics/{chapter-06 => chapter-06-Strings-Cont}/README.md (100%) rename python/learnpython.org/Basics/{chapter-06 => chapter-06-Strings-Cont}/exercise.py (100%) rename python/learnpython.org/Basics/{chapter-06 => chapter-06-Strings-Cont}/strings.py (100%) rename python/learnpython.org/Basics/{chapter-07 => chapter-07-conditionals}/README.md (100%) create mode 100644 python/learnpython.org/Basics/chapter-07-conditionals/example.py create mode 100644 python/learnpython.org/Basics/chapter-07-conditionals/exercise.py create mode 100644 python/learnpython.org/Basics/chapter-08-Loops/README.md create mode 100644 python/learnpython.org/Basics/chapter-08-Loops/example.py create mode 100644 python/learnpython.org/Basics/chapter-08-Loops/exercise.py create mode 100644 python/learnpython.org/Basics/chapter-09-Functions/README.md create mode 100644 python/learnpython.org/Basics/chapter-09-Functions/example.py create mode 100644 python/learnpython.org/Basics/chapter-09-Functions/exercise.py diff --git a/python/learnpython.org/Basics/chapter-01/README.md b/python/learnpython.org/Basics/chapter-01-helloWorld/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-01/README.md rename to python/learnpython.org/Basics/chapter-01-helloWorld/README.md diff --git a/python/learnpython.org/Basics/chapter-01/helloworld.py b/python/learnpython.org/Basics/chapter-01-helloWorld/helloworld.py similarity index 100% rename from python/learnpython.org/Basics/chapter-01/helloworld.py rename to python/learnpython.org/Basics/chapter-01-helloWorld/helloworld.py diff --git a/python/learnpython.org/Basics/chapter-02/README.md b/python/learnpython.org/Basics/chapter-02-Variables/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-02/README.md rename to python/learnpython.org/Basics/chapter-02-Variables/README.md diff --git a/python/learnpython.org/Basics/chapter-02/arithmetic.py b/python/learnpython.org/Basics/chapter-02-Variables/arithmetic.py similarity index 100% rename from python/learnpython.org/Basics/chapter-02/arithmetic.py rename to python/learnpython.org/Basics/chapter-02-Variables/arithmetic.py diff --git a/python/learnpython.org/Basics/chapter-02/exercise.py b/python/learnpython.org/Basics/chapter-02-Variables/exercise.py similarity index 100% rename from python/learnpython.org/Basics/chapter-02/exercise.py rename to python/learnpython.org/Basics/chapter-02-Variables/exercise.py diff --git a/python/learnpython.org/Basics/chapter-02/floating-point.py b/python/learnpython.org/Basics/chapter-02-Variables/floating-point.py similarity index 100% rename from python/learnpython.org/Basics/chapter-02/floating-point.py rename to python/learnpython.org/Basics/chapter-02-Variables/floating-point.py diff --git a/python/learnpython.org/Basics/chapter-02/integers.py b/python/learnpython.org/Basics/chapter-02-Variables/integers.py similarity index 100% rename from python/learnpython.org/Basics/chapter-02/integers.py rename to python/learnpython.org/Basics/chapter-02-Variables/integers.py diff --git a/python/learnpython.org/Basics/chapter-02/strings.py b/python/learnpython.org/Basics/chapter-02-Variables/strings.py similarity index 100% rename from python/learnpython.org/Basics/chapter-02/strings.py rename to python/learnpython.org/Basics/chapter-02-Variables/strings.py diff --git a/python/learnpython.org/Basics/chapter-03/README.md b/python/learnpython.org/Basics/chapter-03-Lists/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-03/README.md rename to python/learnpython.org/Basics/chapter-03-Lists/README.md diff --git a/python/learnpython.org/Basics/chapter-03/example.py b/python/learnpython.org/Basics/chapter-03-Lists/example.py similarity index 100% rename from python/learnpython.org/Basics/chapter-03/example.py rename to python/learnpython.org/Basics/chapter-03-Lists/example.py diff --git a/python/learnpython.org/Basics/chapter-03/exercise.py b/python/learnpython.org/Basics/chapter-03-Lists/exercise.py similarity index 100% rename from python/learnpython.org/Basics/chapter-03/exercise.py rename to python/learnpython.org/Basics/chapter-03-Lists/exercise.py diff --git a/python/learnpython.org/Basics/chapter-04/README.md b/python/learnpython.org/Basics/chapter-04-Mathematics/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-04/README.md rename to python/learnpython.org/Basics/chapter-04-Mathematics/README.md diff --git a/python/learnpython.org/Basics/chapter-04/arithmetic.py b/python/learnpython.org/Basics/chapter-04-Mathematics/arithmetic.py similarity index 100% rename from python/learnpython.org/Basics/chapter-04/arithmetic.py rename to python/learnpython.org/Basics/chapter-04-Mathematics/arithmetic.py diff --git a/python/learnpython.org/Basics/chapter-04/exercise.py b/python/learnpython.org/Basics/chapter-04-Mathematics/exercise.py similarity index 100% rename from python/learnpython.org/Basics/chapter-04/exercise.py rename to python/learnpython.org/Basics/chapter-04-Mathematics/exercise.py diff --git a/python/learnpython.org/Basics/chapter-04/joining-strings.py b/python/learnpython.org/Basics/chapter-04-Mathematics/joining-strings.py similarity index 100% rename from python/learnpython.org/Basics/chapter-04/joining-strings.py rename to python/learnpython.org/Basics/chapter-04-Mathematics/joining-strings.py diff --git a/python/learnpython.org/Basics/chapter-05/README.md b/python/learnpython.org/Basics/chapter-05-Strings/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-05/README.md rename to python/learnpython.org/Basics/chapter-05-Strings/README.md diff --git a/python/learnpython.org/Basics/chapter-05/exercise.py b/python/learnpython.org/Basics/chapter-05-Strings/exercise.py similarity index 100% rename from python/learnpython.org/Basics/chapter-05/exercise.py rename to python/learnpython.org/Basics/chapter-05-Strings/exercise.py diff --git a/python/learnpython.org/Basics/chapter-05/string-formatting.py b/python/learnpython.org/Basics/chapter-05-Strings/string-formatting.py similarity index 100% rename from python/learnpython.org/Basics/chapter-05/string-formatting.py rename to python/learnpython.org/Basics/chapter-05-Strings/string-formatting.py diff --git a/python/learnpython.org/Basics/chapter-06/README.md b/python/learnpython.org/Basics/chapter-06-Strings-Cont/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-06/README.md rename to python/learnpython.org/Basics/chapter-06-Strings-Cont/README.md diff --git a/python/learnpython.org/Basics/chapter-06/exercise.py b/python/learnpython.org/Basics/chapter-06-Strings-Cont/exercise.py similarity index 100% rename from python/learnpython.org/Basics/chapter-06/exercise.py rename to python/learnpython.org/Basics/chapter-06-Strings-Cont/exercise.py diff --git a/python/learnpython.org/Basics/chapter-06/strings.py b/python/learnpython.org/Basics/chapter-06-Strings-Cont/strings.py similarity index 100% rename from python/learnpython.org/Basics/chapter-06/strings.py rename to python/learnpython.org/Basics/chapter-06-Strings-Cont/strings.py diff --git a/python/learnpython.org/Basics/chapter-07/README.md b/python/learnpython.org/Basics/chapter-07-conditionals/README.md similarity index 100% rename from python/learnpython.org/Basics/chapter-07/README.md rename to python/learnpython.org/Basics/chapter-07-conditionals/README.md diff --git a/python/learnpython.org/Basics/chapter-07-conditionals/example.py b/python/learnpython.org/Basics/chapter-07-conditionals/example.py new file mode 100644 index 0000000..c92b13c --- /dev/null +++ b/python/learnpython.org/Basics/chapter-07-conditionals/example.py @@ -0,0 +1,62 @@ +#! /bin/python3 + +x = 2 + +print ("x = 2") +print ("x == 2", x == 2) +print ("x == 3", x == 3) +print ("x != 2", x != 2) + + +name = "John" +age = 35 + +if name == "John" and age == 35: + print("This is an indented statement, becaues it's inside an if clause.") +if name == "John" and age > 33: + print("This is printed from an second if statement!") +else: + print("None of the conditions were true") + +#Now we'll iterate through lists + +listNames = ["John", "Rick", "Morty"] +#Remeber the name variable is already set to "John" +if name in listNames: + print("Found the name 'John' inside the listNames variable!") + +#Now well dive into Code Blocks!! + +statement = False +anotherStatement = True + +if statement is True: + #this is a code block! + print("If statement was true, this would print out. But its set to False.") + pass +elif anotherStatement is True: + #another nested code block under the elif statement! + print("\n\nWe have found the variable anotherStatement as True") + pass +else: + print("Nothing has evaluated") + pass + +#Now wel start to use the "is" operator + +list1 = [1, 2, 3] +list2 = ["one", "two", "three"] +list3 = [1, 2, 3] + +print ("\n\nlist1 : ", list1, "\nlist2 : ", list2, "\nlist3 : ", list3) +print ("list1 == list2 : ", list1 == list2) +print ("list1 is list2 : ", list1 is list2) +print ("list1 == list3 : ", list1 == list3) +print ("list 1 is list3 : ", list1 is list3) + + +#now time for the not operator + +print ("\n\nnot False : ", not False) +print ("(not False) == False : ", (not False) == False) + diff --git a/python/learnpython.org/Basics/chapter-07-conditionals/exercise.py b/python/learnpython.org/Basics/chapter-07-conditionals/exercise.py new file mode 100644 index 0000000..0bcc8d3 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-07-conditionals/exercise.py @@ -0,0 +1,25 @@ +#Change the variables in the first section, so that each if statement resolves as True. + +# change this code +number = 16 +second_number = 0 +first_array = [1,2,3] +second_array = [1,2] + +if number > 15: + print("1") + +if first_array: + print("2") + +if len(second_array) == 2: + print("3") + +if len(first_array) + len(second_array) == 5: + print("4") + +if first_array and first_array[0] == 1: + print("5") + +if not second_number: + print("6") diff --git a/python/learnpython.org/Basics/chapter-08-Loops/README.md b/python/learnpython.org/Basics/chapter-08-Loops/README.md new file mode 100644 index 0000000..9317bec --- /dev/null +++ b/python/learnpython.org/Basics/chapter-08-Loops/README.md @@ -0,0 +1,20 @@ +Loops + +There are two types of loops in Python, for and while + + +Exercise + +Loop through and print out all even numbers from the numbers list in the same order they are received. Don't print any numbers that come after 237 in the sequence. + +numbers = [ + 951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544, + 615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941, + 386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345, + 399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217, + 815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717, + 958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470, + 743, 527 +] + +# your code goes here diff --git a/python/learnpython.org/Basics/chapter-08-Loops/example.py b/python/learnpython.org/Basics/chapter-08-Loops/example.py new file mode 100644 index 0000000..38ea9f0 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-08-Loops/example.py @@ -0,0 +1,50 @@ +#!/bin/python3 + +#for loops + +primes = [2, 3, 5, 7, 11, 13, 17] + +for prime in primes: + print(prime) + + +#Now well play with the range() command +print("\n\n Playing with range(5)") +for x in range(5): + print(x) + +print("\nrange(3,6)") +for x in range(3,6): + print(x) + +print ("\n Lets print out even numbers using range(2,20,2)") +print ("Notice how the first digit includes the index specified, but the second integer EXCLUDES the index specified!") + +for x in range(2,20,2): + print(x) + +#Now time to play with while loops +print("\n\nNow it's time for while loops!") + +count = 0 +while count <= 10: + print(count) + count += 1 #same as count = count + 1 + +#Time to initiate a break in the while loop +print("\n\nUsing the break command in a while loop") + +count = 0 +while True: + print(count) + count += 1 + if count > 10: + print("count variable has exceeded 10!!") + break +print("\n\nLets print only Odd numbers") +for x in range(30): + #here we check if x is even + if x % 2 == 0: #if x divided by two has a remainded or 0, we have an even number! + continue + print(x) + diff --git a/python/learnpython.org/Basics/chapter-08-Loops/exercise.py b/python/learnpython.org/Basics/chapter-08-Loops/exercise.py new file mode 100644 index 0000000..401ca41 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-08-Loops/exercise.py @@ -0,0 +1,18 @@ +numbers = [ + 951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544, + 615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941, + 386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345, + 399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217, + 815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717, + 958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470, + 743, 527 +] + +for i in numbers: + if i != 237: + if i % 2 == 0: + print(i) + elif i == 237: + break + + diff --git a/python/learnpython.org/Basics/chapter-09-Functions/README.md b/python/learnpython.org/Basics/chapter-09-Functions/README.md new file mode 100644 index 0000000..f83ae96 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-09-Functions/README.md @@ -0,0 +1,5 @@ +Functions + +What are Functions? + +Functions are a convenient way to divide your code into useful blocks, allowing us to order our code, make it more readable, reuse it and save some time. Also functions are a key way to define interfaces so programmers can share their code. diff --git a/python/learnpython.org/Basics/chapter-09-Functions/example.py b/python/learnpython.org/Basics/chapter-09-Functions/example.py new file mode 100644 index 0000000..2c4e7ae --- /dev/null +++ b/python/learnpython.org/Basics/chapter-09-Functions/example.py @@ -0,0 +1,38 @@ +#!/bin/python3 + + +def first_function(): + print("Hello World") + print("From inside a funtion") + +first_function() + + +def second_function(name, age): + print("Hello %s, You're getting kind of old at %d. Don't you think?" % (name,age)) + return name + str(age) + +second_function("John", 35) + + +#******COPIED FROM THE WEBSITE*** +print("\n\nEverything from here down was copied and pasted from website!!") +# Define our 3 functions +def my_function(): + print("Hello From My Function!") + +def my_function_with_args(username, greeting): + print("Hello, %s, From My Function!, I wish you %s"%(username, greeting)) + +def sum_two_numbers(a, b): + return a + b + +# print(a simple greeting) +my_function() + +#prints - "Hello, John Doe, From My Function!, I wish you a great year!" +my_function_with_args("John Doe", "a great year!") + +# after this line x will hold the value 3! +x = sum_two_numbers(1,2) +print(x) diff --git a/python/learnpython.org/Basics/chapter-09-Functions/exercise.py b/python/learnpython.org/Basics/chapter-09-Functions/exercise.py new file mode 100644 index 0000000..3113ea2 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-09-Functions/exercise.py @@ -0,0 +1,14 @@ +# Modify this function to return a list of strings as defined above +def list_benefits(): + pass + +# Modify this function to concatenate to each benefit - " is a benefit of functions!" +def build_sentence(benefit): + pass + +def name_the_benefits_of_functions(): + list_of_benefits = list_benefits() + for benefit in list_of_benefits: + print(build_sentence(benefit)) + +name_the_benefits_of_functions()