diff --git a/python/learnpython.org/Basics/chapter-01/README.md b/python/learnpython.org/Basics/chapter-01/README.md new file mode 100644 index 0000000..3ddf723 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-01/README.md @@ -0,0 +1 @@ +This was like any other programming tutorial, and used Hello World as your first program. diff --git a/python/learnpython.org/Basics/chapter-01/helloworld.py b/python/learnpython.org/Basics/chapter-01/helloworld.py new file mode 100644 index 0000000..1fada33 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-01/helloworld.py @@ -0,0 +1,5 @@ +print ("Hello World") + +print ("Use the print(\"\") command") +print ("You do not have to escape Parentheses()") +print ("But you do have to Escape (\) Quotation Marks \"") diff --git a/python/learnpython.org/Basics/chapter-02/README.md b/python/learnpython.org/Basics/chapter-02/README.md new file mode 100644 index 0000000..2d9729f --- /dev/null +++ b/python/learnpython.org/Basics/chapter-02/README.md @@ -0,0 +1,5 @@ +This lesson from learnpython.org covers different types of variables. + +Exercise + +The target of this exercise is to create a string, an integer, and a floating point number. The string should be named mystring and should contain the word "hello". The floating point number should be named myfloat and should contain the number 10.0, and the integer should be named myint and should contain the number 20. diff --git a/python/learnpython.org/Basics/chapter-02/arithmetic.py b/python/learnpython.org/Basics/chapter-02/arithmetic.py new file mode 100644 index 0000000..09b2518 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-02/arithmetic.py @@ -0,0 +1,11 @@ +firstInt = input("Enter first number to add:") +secondInt = input("Enter second number to add:") +arithmeticComment = "I have to wrap the 'finalAsnwer' variable inside the int() function, otherwise the integers are treated as strings!" + +finalAnswer =int(firstInt) + int(secondInt) +wrongFinalAnswer = firstInt + secondInt + +print(firstInt, "+", secondInt, "=", finalAnswer) +print(arithmeticComment) +print("An example of not using the int() function") +print(wrongFinalAnswer) diff --git a/python/learnpython.org/Basics/chapter-02/exercise.py b/python/learnpython.org/Basics/chapter-02/exercise.py new file mode 100644 index 0000000..1a6bca6 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-02/exercise.py @@ -0,0 +1,10 @@ +mystring = "Hello From a String" +myint = 420 +myfloat = 4.20 + +if mystring == "hello": + print("String: %s" % mystring) +if isinstance(myfloat, float) and myfloat == 4.20: + print("Float: %f" % myfloat) +if isinstance(myint, int) and myint == 420: #I copied this line, will learn if statements soon I hope! + print("Integer: %d" % myint) diff --git a/python/learnpython.org/Basics/chapter-02/floating-point.py b/python/learnpython.org/Basics/chapter-02/floating-point.py new file mode 100644 index 0000000..3776be5 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-02/floating-point.py @@ -0,0 +1,6 @@ +firstfloat = 4.20 #Include a decimal after the integer to specify a float +secondfloat = 31.7 + +print (firstfloat) +print (secondfloat) + diff --git a/python/learnpython.org/Basics/chapter-02/integers.py b/python/learnpython.org/Basics/chapter-02/integers.py new file mode 100644 index 0000000..cc5b69f --- /dev/null +++ b/python/learnpython.org/Basics/chapter-02/integers.py @@ -0,0 +1,7 @@ +myInt = 4 +my2ndInt = 2 +finalInt = 0 +intComment = "Integers do not need to be inside quotes!" + +print (myInt,my2ndInt,finalInt) +print (intComment) diff --git a/python/learnpython.org/Basics/chapter-02/strings.py b/python/learnpython.org/Basics/chapter-02/strings.py new file mode 100644 index 0000000..bfa934c --- /dev/null +++ b/python/learnpython.org/Basics/chapter-02/strings.py @@ -0,0 +1,7 @@ +firstString = "You can use Single or Double Quotes to define Strings" +secondString = "With Double Quotes you DON'T have to escape apostrophes (')" +finalString = 'With Single (\') quotes you DO have to escape each apostrophe!' + +print(firstString) +print(secondString) +print(finalString) diff --git a/python/learnpython.org/Basics/chapter-03/README.md b/python/learnpython.org/Basics/chapter-03/README.md new file mode 100644 index 0000000..a472d36 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-03/README.md @@ -0,0 +1,5 @@ +Exercise + +In this exercise, you will need to add numbers and strings to the correct lists using the "append" list method. You must add the numbers 1,2, and 3 to the "numbers" list, and the words 'hello' and 'world' to the strings variable. + +You will also have to fill in the variable second_name with the second name in the names list, using the brackets operator []. Note that the index is zero-based, so if you want to access the second item in the list, its index will be 1. diff --git a/python/learnpython.org/Basics/chapter-03/example.py b/python/learnpython.org/Basics/chapter-03/example.py new file mode 100644 index 0000000..032a1d8 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-03/example.py @@ -0,0 +1,12 @@ +mylist = [] +mylist.append(1) +mylist.append(2) +mylist.append(3) +print (mylist[0]) #Print entry 0, or the first entry! +print (mylist[1]) #Prints the second entry +print (mylist[2]) #Prints the third entry, You never would have guessed!! + +#basic for loop to iterate through your list + +for x in mylist: + print(x, "From inside a for loop") diff --git a/python/learnpython.org/Basics/chapter-03/exercise.py b/python/learnpython.org/Basics/chapter-03/exercise.py new file mode 100644 index 0000000..d17fe2d --- /dev/null +++ b/python/learnpython.org/Basics/chapter-03/exercise.py @@ -0,0 +1,19 @@ +#!/bin/python3 + +numbers = [] +strings = [] +names = ["Robert", "John", "Eric", "Thomas"] +secondName = names[1] + +numbers.append(1) +numbers.append(2) +numbers.append(3) + +strings.append("Hello") +strings.append("world") + +print (numbers) +print (strings) +#print (secondName) +print ("The second name in the name array is: ", secondName) +print ("The second name is %s" % secondName) #I don't understand this technique yet, just copying tutorial code and practicing diff --git a/python/learnpython.org/Basics/chapter-04/README.md b/python/learnpython.org/Basics/chapter-04/README.md new file mode 100644 index 0000000..9872bfa --- /dev/null +++ b/python/learnpython.org/Basics/chapter-04/README.md @@ -0,0 +1,3 @@ +Exercise + +The target of this exercise is to create two lists called x_list and y_list, which contain 10 instances of the variables x and y, respectively. You are also required to create a list called big_list, which contains the variables x and y, 10 times each, by concatenating the two lists you have created. diff --git a/python/learnpython.org/Basics/chapter-04/arithmetic.py b/python/learnpython.org/Basics/chapter-04/arithmetic.py new file mode 100644 index 0000000..e3dc080 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-04/arithmetic.py @@ -0,0 +1,24 @@ +addition = 1 + 4 + 5 + +print ("1 + 4 + 5 = ", addition) + +multiply = 5 * 4 + +print ("5 * 4 = ", multiply) + +leftToRight = 5 + 2 * 10 #Python uses PEMDAS, not basic left to right mathematics + +print("5 + 2 * 10 = ", leftToRight) + +remainder = 11 % 3 +quotient = int(11 / 3) +print("The whole number in a division problem 11 / 3 is :", quotient) +print("11 % 3 leaves a remainder of : ", remainder) + +print ("\n", "Using a Double multiply symbol (**) is for exponents.") + +squared = 7 ** 2 +cubed = 3 ** 3 + +print ("7^2 or seven squared is : ", squared) +print ("3^3 or three cubed is : ", cubed) diff --git a/python/learnpython.org/Basics/chapter-04/exercise.py b/python/learnpython.org/Basics/chapter-04/exercise.py new file mode 100644 index 0000000..ad5cbdd --- /dev/null +++ b/python/learnpython.org/Basics/chapter-04/exercise.py @@ -0,0 +1,38 @@ +x = object() +y = object() + +xList = [] +yList = [] +#bigList = xList + yList + +#Create the X list +xList.append(1) +xList.append(2) +xList.append(3) +xList.append(4) +xList.append(5) +xList.append(6) +xList.append(7) +xList.append(8) +xList.append(9) +xList.append(10) +#Create the Ylist +yList.append(10) +yList.append(9) +yList.append(8) +yList.append(7) +yList.append(6) +yList.append(5) +yList.append(4) +yList.append(3) +yList.append(2) +yList.append(1) + +bigList = (xList + yList) * 10 +print (xList, "\n", yList) +print ("The Big list follows : ", bigList) + +print ("\n", "The X list contains : ", len(xList)) +print ("The Y list contains : ", len(yList)) +print ("The bigList is : ", len(bigList)) + diff --git a/python/learnpython.org/Basics/chapter-04/joining-strings.py b/python/learnpython.org/Basics/chapter-04/joining-strings.py new file mode 100644 index 0000000..d26b0e5 --- /dev/null +++ b/python/learnpython.org/Basics/chapter-04/joining-strings.py @@ -0,0 +1,14 @@ +helloworld = "hello" + " " + "world" +print (helloworld) + +print ("\n", "We can also multiply strings in Python using the * character! ie string = mystring * 10") +moreHelloWorld = helloworld * 10 +print (moreHelloWorld) + +print ("\n", "We can even join lists!") +evenNumbers = [2,4,6,8] +oddNumbers = [1,3,5,7,9] +allNumbers = evenNumbers + oddNumbers +print (allNumbers) +print ("\n", "And even Multiply lists with * !!!") +print (allNumbers * 3)