diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Learning-Python.iml b/.idea/Learning-Python.iml new file mode 100644 index 0000000..d8b3f6c --- /dev/null +++ b/.idea/Learning-Python.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..23231ce --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8581145 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Al Sweigart/.idea/.gitignore b/Al Sweigart/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Al Sweigart/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Al Sweigart/.idea/Al Sweigart.iml b/Al Sweigart/.idea/Al Sweigart.iml new file mode 100644 index 0000000..d8b3f6c --- /dev/null +++ b/Al Sweigart/.idea/Al Sweigart.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Al Sweigart/.idea/inspectionProfiles/profiles_settings.xml b/Al Sweigart/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/Al Sweigart/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Al Sweigart/.idea/misc.xml b/Al Sweigart/.idea/misc.xml new file mode 100644 index 0000000..1d3ce46 --- /dev/null +++ b/Al Sweigart/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Al Sweigart/.idea/modules.xml b/Al Sweigart/.idea/modules.xml new file mode 100644 index 0000000..3b12e3c --- /dev/null +++ b/Al Sweigart/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Al Sweigart/.idea/vcs.xml b/Al Sweigart/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Al Sweigart/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Al Sweigart/01 Python Basics/Notes.MD b/Al Sweigart/01 Python Basics/Notes.MD new file mode 100644 index 0000000..604393f --- /dev/null +++ b/Al Sweigart/01 Python Basics/Notes.MD @@ -0,0 +1,231 @@ +# Learning with Al Sweigart - Automate the boring stuff with Python +REPL, explained; +Read Evaluate Print Loop, this lets us run or execute Python instructions one at time and instantly shows it's output. + +Basic Math Operators in Python + +| Operator | Operation | Example | +|:----|:-----------------:|:---------------:| +| ** | Exponent(raised to the power) | 2 ** 3 = 8 | +| % | Modulus/Remainder | 22 % 8 i.e 2 rem 6 = 6 | +| // | Integer division/round up | 22 // 8 = 2.75, 2.75 rounds up to 2| +| / | Division | 22 / 8 = 2.75 | +| * | Multiplication | 3 * 5 = 15 | +| - | Subtraction | 5 - 2 = 3 | +| + | Addition | 5 + 5 = 10 | + +```py +exponent = 8 ** 4 +modulus = 13 % 2 +round_up = 93 // 5 +divide = 169 / 13 +multiply = 12 * 12 +subtract = 256 - 13 +add = 101 + 102 +# print(round_up) +``` + +The order of Operations in python are called **Precedence**, think, **BODMAS** in Python, __i.e__, **PEDMAS**, in that order, the +former taking precedence; The __(**)__ is evaluated first, then __(*)__, __(/)__, __(//)__, __(%)__ operators are evaluated next; from left +to the right. And the __(+)__, __(-)__ operators are evaluated last _(also from left to right)_. + +**Parenthesis ()**, are used to override the order of things, operations in brackets __()__, are treated first, +_also from left to the right_. + +Whitespace in between values do not matter and are ignored in Python **_(except for indentation -starting on a new line)_**, +but a single space is convention and is overlooked. + +```py +try1= 2 + 2 +try1 = 9 + 9 +print(try1) +``` + +### Integer, **Floating-Points _(Floats)_**, and String Data Types +A data type is a category for values, and every value belongs to exactly one datatype. + +### Common Data Types +**Integers _(int)_** -2, -1, 0, 1, 2, 3, ....
+**floating-points _(floats)_** -1.25, -1.0, -0.5, ...
+**Strings _(str)_** "a", 'b', "c", 'D' 'Hello!'.... + +Strings are always surrounded in single or double quotes __('')__, or __("")__; **_i.e_**, +`'Hello'`, `"Good morning"`, so Python knows where the strings begin and ends, `(' ', or " ")` are called empty strings. + +```py +greetings = "Hello cruel world" +regards = 'Wish you the very same' +empty = " " +print(empty) +``` + +### String Concatenation and Replication +__(+)__ sign is a mathematical operator that sums two or more values of integer types; +**However**, **_(+)_** sign is also used for **concatenating** or **joining** strings. + +```py +friend1 = 'Middleman' +friend2 = "Miles" +friends = friend1 + friend2 # 'Middleman' + "Miles" +print(friends) +``` +The __(*)__ operator, when used on one string value and one integer value, it becomes the string replication operator. + +```py +friend3 = 'Angel' * 5 +print(friend3) +``` + +### Storing values in variables + +A **variable** is like a _box_, this lets us store a single value. +**Assignments** __(=)__; assigns a value of any known datatype to a variable. + +```py +light_yrs = 40 +print(light_yrs) + +nummer = 2 +print(nummer) +print(light_yrs + nummer + light_yrs) + +nummer = nummer + 10 +print(nummer) +``` + +A variable is created when a value is stored or assigned to it. +After that, the variable name can be called as their expressions or by name with other variables and values. When a variable is assigned a new value, the old value is forgotten. + +```py +nummer = 2 +print(nummer) +nummer = nummer + 10 +print(nummer) +``` + +### Variable Names + +An ideal Variable name describes the data it contains. One can name a variable +almost anything, under certain rules ofcourse; Python have some restrictions when it +comes to name variables. A good Variable in Python follows these rules; + +__one word no spaces__ (eg; variable name | variableName)
+use only letters, numbers and the underscore(_) character no hyphens(-).
+variables names can't begin with a number (eg; 15boxes | box15) + +Variable names are _case-sensitive_, in the sense that _box_, **BOX**, `Box`, _`bOX`_, are +different variables. It is a Python convention to start variables with lowercase +letters. __(eg; Find = 'works ✅' but find = "is preferred")__. + +**camelCasing** or **under_score** as variable naming styles are advised. + + +**When there are no more lines of code to execute, the Python program terminates, and stops running. +When a Python file is ran, it starts from the top, working it's way down, executes the inputted commands +until the last line, then the Python program exits.** + +### Comments +```py +# This entire area is commented and won't be executed when ran. +``` +Python ignores comments, and can be used to leave notes or to explain what a particular line of code does to others. + +```py +# (#) for single line comments + +""" +for multiple lines +for multiple lines +for multiple lines +""" + +``` + +### Print() Function +The `print()` function displays the string value inside it's parenthesis on the screen when you run the code. + +```py +print('Hello, treacherous world!') +print('How many fingers am I holding up?') # Then run +``` + +### Input() Function +The `input()` function waits for the user to type some text on the keyboard and press +**ENTER**. Here the function asks for a particular datatype, Strings **_(str)_** most times; and +you can fill it in directly in the terminal. + +```py +myOtherName = input("What is your name? ") # Stores value to the variable 'myOtherName +print('Your name is ' + myOtherName) +''' +NOTE!!! input() functions are only available in versions of Python3, may not work if running Python2 +''' +``` + +### Len() Function +The `len()` function, you can pass in a string value **(or a variable containing string)**, +and the function evaluates to the integer value of the total number of characters +**(letters)** in that string. + +```py +frankOceanSaid = 'I can never make him love me' +print(len(frankOceanSaid)) +''' +print() : shows us the output, len(), counts and gives the number of characters +''' +``` + +### Integer + String concatenation errors + +```py +# print('I am ' + 29 + 'years old') # 29 is an integer(int), can only concatenate strings(str). +``` + +Python gives an **~~error~~** cuz' the __(+)__ operator can only be used to add two integers +together or concatenate two strings. You can't add an integer to a string, doesn't +follow Pythons grammar rules. One can alter the code to print **_integers(int)_** as +**_stings(str)_**. + +### The `str()`, `int()`, and `float()` Functions +___str()___ : this converts to the string version of the integer within
+__int()__ : also useful for rounding down a floating-point(floats) number + +```py +num = 33 +print('I am ' + str(num) + 'years old') + +str(-3.14) # Python sees a string, equivalent to 'A', and can't be calculated +str(0) +int('42') +int('-99') +int(7.7) # clearly a float datatype, outputs 7.7 ".7 is > .5", rounds down to 8. +float('3.14') +float(10) # turns to 10.0 +``` + +### Text and number equivalence +An integer can be equal to a floating point number + +44 == '44' :False, '44', is a string
+44 == 44.0 :True, integers(int) rounds down to 44
+44.0 == 0044.000 :True, ignores the zero's before 44, they are insignificant + +Integers and floats are mathematically numbers. + + +## FIRST PROGRAM +#### This program says hello and asks for users name. +```py +print('Hello, cruel world!') +print('What is your name?') + +myName = input() +print('It is good to meet you, ' + myName) + +print('The length of my name has got to be: ') +print(len(myName)) + +print('How old are you?') +myAge = input() +print('I will be ' + str(int(myAge) + 1) + ' in a year!') +``` \ No newline at end of file diff --git a/Al Sweigart/01 Python Basics/python problems/test1.py b/Al Sweigart/01 Python Basics/python problems/test1.py new file mode 100644 index 0000000..b0e1f86 --- /dev/null +++ b/Al Sweigart/01 Python Basics/python problems/test1.py @@ -0,0 +1,5 @@ +# Write a program that asks the user for their birth year, and prints how old they’ll be in the year 2050. + +ask4BirthYear = int(input("What year were you born? ")) +yearConstant = 2050 +print("You are going to be " + str(yearConstant - ask4BirthYear) + " years old in the year 2050") diff --git a/Al Sweigart/01 Python Basics/python problems/test2.py b/Al Sweigart/01 Python Basics/python problems/test2.py new file mode 100644 index 0000000..12ac75c --- /dev/null +++ b/Al Sweigart/01 Python Basics/python problems/test2.py @@ -0,0 +1,3 @@ +# Modify test1: also ask for their birth month & day, and tell them whether they've had their birthday +# yet this year (relative to today). (Work with date arithmetic manually or use datetime.) + diff --git a/Al Sweigart/01 Python Basics/python problems/test3.py b/Al Sweigart/01 Python Basics/python problems/test3.py new file mode 100644 index 0000000..c6143d5 --- /dev/null +++ b/Al Sweigart/01 Python Basics/python problems/test3.py @@ -0,0 +1,5 @@ +# Create a “tip calculator”: ask user for bill amount and tip percentage (like “15%”), compute tip and total. + + + + diff --git a/Al Sweigart/02 Flow Control/index.py b/Al Sweigart/02 Flow Control/index.py new file mode 100644 index 0000000..e69de29