working on exercises
This commit is contained in:
parent
c78526aefd
commit
02d3b0ebe9
1
python/learnpython.org/Basics/chapter-01/README.md
Normal file
1
python/learnpython.org/Basics/chapter-01/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
This was like any other programming tutorial, and used Hello World as your first program.
|
||||||
5
python/learnpython.org/Basics/chapter-01/helloworld.py
Normal file
5
python/learnpython.org/Basics/chapter-01/helloworld.py
Normal file
@ -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 \"")
|
||||||
5
python/learnpython.org/Basics/chapter-02/README.md
Normal file
5
python/learnpython.org/Basics/chapter-02/README.md
Normal file
@ -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.
|
||||||
11
python/learnpython.org/Basics/chapter-02/arithmetic.py
Normal file
11
python/learnpython.org/Basics/chapter-02/arithmetic.py
Normal file
@ -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)
|
||||||
10
python/learnpython.org/Basics/chapter-02/exercise.py
Normal file
10
python/learnpython.org/Basics/chapter-02/exercise.py
Normal file
@ -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)
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
firstfloat = 4.20 #Include a decimal after the integer to specify a float
|
||||||
|
secondfloat = 31.7
|
||||||
|
|
||||||
|
print (firstfloat)
|
||||||
|
print (secondfloat)
|
||||||
|
|
||||||
7
python/learnpython.org/Basics/chapter-02/integers.py
Normal file
7
python/learnpython.org/Basics/chapter-02/integers.py
Normal file
@ -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)
|
||||||
7
python/learnpython.org/Basics/chapter-02/strings.py
Normal file
7
python/learnpython.org/Basics/chapter-02/strings.py
Normal file
@ -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)
|
||||||
5
python/learnpython.org/Basics/chapter-03/README.md
Normal file
5
python/learnpython.org/Basics/chapter-03/README.md
Normal file
@ -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.
|
||||||
12
python/learnpython.org/Basics/chapter-03/example.py
Normal file
12
python/learnpython.org/Basics/chapter-03/example.py
Normal file
@ -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")
|
||||||
19
python/learnpython.org/Basics/chapter-03/exercise.py
Normal file
19
python/learnpython.org/Basics/chapter-03/exercise.py
Normal file
@ -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
|
||||||
3
python/learnpython.org/Basics/chapter-04/README.md
Normal file
3
python/learnpython.org/Basics/chapter-04/README.md
Normal file
@ -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.
|
||||||
24
python/learnpython.org/Basics/chapter-04/arithmetic.py
Normal file
24
python/learnpython.org/Basics/chapter-04/arithmetic.py
Normal file
@ -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)
|
||||||
38
python/learnpython.org/Basics/chapter-04/exercise.py
Normal file
38
python/learnpython.org/Basics/chapter-04/exercise.py
Normal file
@ -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))
|
||||||
|
|
||||||
14
python/learnpython.org/Basics/chapter-04/joining-strings.py
Normal file
14
python/learnpython.org/Basics/chapter-04/joining-strings.py
Normal file
@ -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)
|
||||||
Loading…
x
Reference in New Issue
Block a user