├── Python-Projects ├── Hello-World │ ├── hello_world.py │ ├── printing.py │ └── README.md ├── flask │ ├── templates │ │ ├── footer.html │ │ ├── about.html │ │ ├── contact.html │ │ ├── index.html │ │ └── header.html │ ├── __pycache__ │ │ └── hello.cpython-37.pyc │ └── hello.py ├── Math │ ├── sum.py │ ├── mymath.py │ └── README.md ├── Input │ ├── input.py │ └── README.md ├── geo.py ├── google_scraper.py ├── Variables │ ├── variables.py │ └── README.md ├── Conditional Statements │ ├── if.py │ └── README.md ├── Happy-Hour │ ├── happy_hour.py │ └── README.md ├── web.py ├── Logical_Operators │ ├── boolean_practice.py │ ├── boolean_practice_solutions.py │ └── README.md ├── send_sms.py ├── FizzBuzz_Challenge │ ├── fizzbuzz.py │ └── README.md ├── Strings │ ├── strings.py │ └── README.md ├── Functions │ └── functions.py ├── weather.py ├── Python_Lists │ ├── lists.py │ └── README.md ├── Dictionary │ ├── dictionaries.py │ └── README.md └── notebook_intro.ipynb ├── Python-Homeworks ├── tip-submission_4.py ├── tip_submission_5.py ├── tip_submission_1.py ├── README.md ├── tip_submission_2.py └── tip_submission_3.py ├── README.md ├── 1-Python-Syllabus.md ├── 2-Python-Data-Structure.md └── 0-Python-Setup.md /Python-Projects/Hello-World/hello_world.py: -------------------------------------------------------------------------------- 1 | print("Hello World!") -------------------------------------------------------------------------------- /Python-Projects/flask/templates/footer.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Python-Projects/Math/sum.py: -------------------------------------------------------------------------------- 1 | val1 = 6; 2 | val2 = 10; 3 | 4 | #sum 5 | val3 = val1 + val2; 6 | 7 | print (val3) -------------------------------------------------------------------------------- /Python-Projects/flask/templates/about.html: -------------------------------------------------------------------------------- 1 | {% include 'header.html' %} 2 | 3 |

About Page

4 | 5 | {% include 'footer.html' %} 6 | -------------------------------------------------------------------------------- /Python-Projects/flask/templates/contact.html: -------------------------------------------------------------------------------- 1 | {% include 'header.html' %} 2 | 3 |

Contact

4 | 5 | {% include 'footer.html' %} 6 | -------------------------------------------------------------------------------- /Python-Projects/flask/templates/index.html: -------------------------------------------------------------------------------- 1 | {% include 'header.html' %} 2 | 3 |

Homepage

4 | 5 | {% include 'footer.html' %} 6 | 7 | -------------------------------------------------------------------------------- /Python-Projects/flask/__pycache__/hello.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s-shemmee/Python-101/HEAD/Python-Projects/flask/__pycache__/hello.cpython-37.pyc -------------------------------------------------------------------------------- /Python-Projects/Input/input.py: -------------------------------------------------------------------------------- 1 | name = input("What's your name? ") 2 | age = int(input("How old are you? ")) 3 | age_in_dog_years = age * 7 4 | 5 | print(f"{name} you are {age_in_dog_years} in dog years. Woof!") -------------------------------------------------------------------------------- /Python-Projects/geo.py: -------------------------------------------------------------------------------- 1 | from geopy.geocoders import Nominatim 2 | geolocator = Nominatim(user_agent="specify_your_app_name_here") 3 | location = geolocator.geocode("97 Wythe Ave Brooklyn") 4 | print(location.address) 5 | 6 | print((location.latitude, location.longitude)) 7 | 8 | lat = location.latitude -------------------------------------------------------------------------------- /Python-Projects/google_scraper.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import requests 3 | 4 | response = requests.get("http://www.google.com") 5 | soup = BeautifulSoup(response.text, "html.parser") 6 | 7 | links = soup.find_all('a') 8 | 9 | for link in links: 10 | print(link.get_text()) -------------------------------------------------------------------------------- /Python-Projects/Variables/variables.py: -------------------------------------------------------------------------------- 1 | # Variables are just nicknames 2 | # they're plain, lowercase words 3 | # examples: x, y, banana, phone_a_quail 4 | 5 | name = "Mattan Griffel" 6 | orphan_fee = 200 7 | teddy_bear_fee = 121.80 8 | 9 | total = orphan_fee + teddy_bear_fee 10 | 11 | print(name, "the total will be", total) -------------------------------------------------------------------------------- /Python-Projects/Math/mymath.py: -------------------------------------------------------------------------------- 1 | # + plus 2 | # - minus 3 | # / divide 4 | # * times 5 | # ** exponentiation 6 | # % modulo 7 | # < less than 8 | # > greater than 9 | 10 | print("What is the answer to life, the universe, and everything?", int((40 + 30 - 7) * 2 / 3)) 11 | 12 | print("Is it true that 5 * 2 > 3 * 4?") 13 | 14 | print(5 * 2 > 3 * 4) 15 | 16 | print("What is 5 * 2?", 5 * 2) 17 | print("What is 3 * 4?", 3 * 4) -------------------------------------------------------------------------------- /Python-Homeworks/tip-submission_4.py: -------------------------------------------------------------------------------- 1 | # type a script that take the bill amound and give u the tip of 5% 10% 15% and 20% 2 | 3 | bill = float(input("What is your the bill, please ?").strip('$')) 4 | 5 | tip_5 = bill * 0.5 6 | tip_10 = bill * 0.10 7 | tip_15 = bill * 0.15 8 | tip_20 = bill * 0.20 9 | 10 | print(f"So you tips are for 5% is {tip_5:.2f}$, for 10% is {tip_10:.2f}$, for 15% is{tip_15:.2f}$, and for 20% is {tip_20:.2f}$") -------------------------------------------------------------------------------- /Python-Projects/Conditional Statements/if.py: -------------------------------------------------------------------------------- 1 | answer = input("Do you want to hear a joke? ") 2 | 3 | affirmative_responses = ["yes", "y"] 4 | negative_responses = ["no", "n"] 5 | 6 | if answer.lower() in affirmative_responses: 7 | print("I'm against picketing, but I don't know how to show it.") 8 | # Mitch Hedburg (RIP) 9 | elif answer.lower() in negative_responses: 10 | print("Fine.") 11 | else: 12 | print("I don't understand.") -------------------------------------------------------------------------------- /Python-Homeworks/tip_submission_5.py: -------------------------------------------------------------------------------- 1 | # Write a script that takes a dollar amount and recommennds a tip (15%, 18% and 20%) 2 | 3 | total = float(input("What is your bill sub-total? ").strip('$')) 4 | 5 | tip_15 = total * 0.15 6 | tip_18 = total * 0.18 7 | tip_20 = total * 0.20 8 | 9 | print("Tip Suggestions:") 10 | print("----------------") 11 | print(f"15% is ${tip_15:.2f}") 12 | print(f"18% is ${tip_18:.2f}") 13 | print(f"20% is ${tip_20:.2f}") -------------------------------------------------------------------------------- /Python-Homeworks/tip_submission_1.py: -------------------------------------------------------------------------------- 1 | # Write a script that takes a dollar amount and recommennds a tip (15%, 18% and 20%) 2 | # Get a name 3 | name = int("What is your name? ") 4 | print(name) 5 | 6 | total = int(float(input("What is your bill sub-total? ").replace('$', ''))) 7 | print(total) 8 | 9 | tip_15 = total * 0.15 10 | tip_18 = total * 0.18 11 | tip_20 = total * 0.20 12 | 13 | print(f"15% is ${tip_15:.2f}") 14 | print(f"18% is ${tip_18:.2f}") 15 | print(f"20% is ${tip_20:.2f}") -------------------------------------------------------------------------------- /Python-Projects/flask/hello.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | app = Flask(__name__) 3 | 4 | @app.route("/") 5 | def index(): 6 | title = "Homepage" 7 | return render_template("index.html", title=title) 8 | 9 | @app.route("/about") 10 | def about(): 11 | title = "About" 12 | return render_template("about.html",title=title) 13 | 14 | @app.route("/contact") 15 | def contact(): 16 | title = "Contact" 17 | return render_template("contact.html",title=title) -------------------------------------------------------------------------------- /Python-Projects/Happy-Hour/happy_hour.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | Places = ["MacDo", 4 | "LCW", 5 | "Marjan", 6 | "Picsin", 7 | "Burger King", 8 | "Hamam"] 9 | 10 | people = ["Ali", 11 | "Hamza", 12 | "Hassan Sensei", 13 | "Salma", 14 | "Ghelo", 15 | "Sokky", 16 | "Robi", 17 | "Oummy"] 18 | 19 | random_place = random.choice(Places) 20 | random_person_one = random.choice(people) 21 | random_person_two = random.choice(people) 22 | 23 | print(f"How about you go to {random_place} with {random_person_one} and {random_person_two}?") 24 | -------------------------------------------------------------------------------- /Python-Projects/web.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | from googlefinance import getQuotes 3 | app = Flask(__name__) 4 | 5 | def get_stock_price(ticker): 6 | return f"{ticker} is trading at ${getQuotes(ticker)[0]['LastTradePrice']}" 7 | 8 | @app.route("/") 9 | def index(): 10 | greeting = "Hello from One Month Python!" 11 | return render_template("index.html", greeting=greeting) 12 | 13 | @app.route("/") 14 | def stock_price(ticker): 15 | price = get_stock_price(ticker) 16 | return render_template("stock_price.html", price=price) 17 | 18 | if __name__ == "__main__": 19 | app.run(debug=True) -------------------------------------------------------------------------------- /Python-Projects/Logical_Operators/boolean_practice.py: -------------------------------------------------------------------------------- 1 | True and True 2 | False and True 3 | 1 == 1 and 2 == 1 4 | "love" == "love" 5 | 1 == 1 or 2 != 1 6 | True and 1 == 1 7 | False and 0 != 0 8 | True or 1 == 1 9 | "time" == "money" 10 | 1 != 0 and 2 == 1 11 | "I Can't Believe It's Not Butter!" != "butter" 12 | "one" == 1 13 | not (True and False) 14 | not (1 == 1 and 0 != 1) 15 | not (10 == 1 or 1000 == 1000) 16 | not (1 != 10 or 3 == 4) 17 | not ("love" == "love" and "time" == "money") 18 | 1 == 1 and (not ("one" == 1 or 1 == 0)) 19 | "chunky" == "bacon" and (not (3 == 4 or 3 == 3)) 20 | 3 == 3 and (not ("love" == "love" or "Python" == "Fun")) -------------------------------------------------------------------------------- /Python-Projects/flask/templates/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% if title=="About" %} 6 | About Page | OneMonth.com 7 | {% elif title=="Contact" %} 8 | Contact Page 9 | {% else %} 10 | OneMonth.com 11 | {% endif %} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Homepage 21 | About Me 22 | Contact 23 | -------------------------------------------------------------------------------- /Python-Projects/send_sms.py: -------------------------------------------------------------------------------- 1 | from twilio.rest import Client 2 | from googlefinance import getQuotes 3 | 4 | def get_stock_price(ticker): 5 | return f"{ticker} is trading at ${getQuotes(ticker)[0]['LastTradePrice']}" 6 | 7 | def send_text(message): 8 | account = "AC9c5237acf6f9474baff618edcc116939" 9 | token = "24805c5150cdaf85727269c24617b1cf" 10 | client = Client(account, token) 11 | 12 | message = client.messages.create(to="+12016473233", from_="+16464900357", 13 | body=message) 14 | 15 | stocks = ["AAPL", "GOOG", "FB"] 16 | 17 | for stock in stocks: 18 | send_text(get_stock_price(stock)) -------------------------------------------------------------------------------- /Python-Projects/FizzBuzz_Challenge/fizzbuzz.py: -------------------------------------------------------------------------------- 1 | # Write a program that prints the numbers from 1 to 100 2 | # But for multiples of three print "Fizz" instead of the number 3 | # and for multiples of five print "Buzz". For multiples of 4 | # both three and five print "FizzBuzz" 5 | 6 | # Hint: % (modulo) tells you what's left over when you divide one number by another 7 | # ex. number % 3 == 0 8 | 9 | for number in range(1, 101): 10 | if number % 3 == 0 and number % 5 == 0: 11 | print("FizzBuzz") 12 | elif number % 3 == 0: 13 | print("Fizz") 14 | elif number % 5 == 0: 15 | print("Buzz") 16 | else: 17 | print(number) -------------------------------------------------------------------------------- /Python-Projects/Strings/strings.py: -------------------------------------------------------------------------------- 1 | # Strings are text surrounded by quotes 2 | # Both single (') or double (") or triple (""") quotes are used 3 | # examples: "dinosaurs", '2112', "I'm lovin' it!" 4 | 5 | kanye_quote = """My greatest pain in life 6 | is that I will never be able 7 | to see myself perform live.""" 8 | 9 | print(kanye_quote) 10 | 11 | hamilton_quote = 'Well, the word got around, they said, "This kid\'s insane, man"' 12 | 13 | print(hamilton_quote) 14 | 15 | name = "Mattan Griffel" 16 | orphan_fee = 200 17 | teddy_bear_fee = 121.8 18 | 19 | total = orphan_fee + teddy_bear_fee 20 | 21 | # print(name, "the total will be", total) 22 | print(f"{name} the total will be ${total:.2f}") -------------------------------------------------------------------------------- /Python-Projects/Hello-World/printing.py: -------------------------------------------------------------------------------- 1 | # "since feeling is first" by e. e. cummings 2 | print("since feeling is first") 3 | print("who pays any attention") 4 | print("to the syntax of things") 5 | print("will never wholly kiss you;") 6 | print("wholly to be a fool") 7 | print("while Spring is in the world") 8 | print() 9 | print("my blood approves") 10 | print("and kisses are a better fate") 11 | print("than wisdom") 12 | print("lady i swear by all flowers. Don't cry") 13 | # I love this line. 14 | print("—the best gesture of my brain is less than") 15 | print("your eyelids' flutter which says") 16 | print() 17 | print("we are for each other: then") 18 | print("laugh, leaning back in my arms") 19 | print("for life's not a paragraph") 20 | print() 21 | print("and death i think is no parenthesis") -------------------------------------------------------------------------------- /Python-Projects/Logical_Operators/boolean_practice_solutions.py: -------------------------------------------------------------------------------- 1 | True and True # True 2 | False and True # False 3 | 1 == 1 and 2 == 1 # False 4 | "love" == "love" # True 5 | 1 == 1 or 2 != 1 # True 6 | True and 1 == 1 # True 7 | False and 0 != 0 # False 8 | True or 1 == 1 # True 9 | "time" == "money" # False 10 | 1 != 0 and 2 == 1 # False 11 | "I Can't Believe It's Not Butter!" != "butter" # True 12 | "one" == 1 # False 13 | not (True and False) # True 14 | not (1 == 1 and 0 != 1) # False 15 | not (10 == 1 or 1000 == 1000) # False 16 | not (1 != 10 or 3 == 4) # False 17 | not ("love" == "love" and "time" == "money") # True 18 | 1 == 1 and (not ("one" == 1 or 1 == 0)) # True 19 | "chunky" == "bacon" and (not (3 == 4 or 3 == 3)) # False 20 | 3 == 3 and (not ("love" == "love" or "Python" == "Fun")) # False -------------------------------------------------------------------------------- /Python-Homeworks/README.md: -------------------------------------------------------------------------------- 1 | # Homework-One : Tip Calculator 2 | 3 | *We've looked at Python variables, strings, arithmetic operators, debugging, typecasting and more! Now, you will put this knowledge to use. It's assignment time!* 4 | 5 | ## Topics we've covered this week: 6 | 7 | - Command line basics (`pwd`, `ls`, `cd`, `open` / `start`, `.`, `..`, `~`), 8 | - Two ways of running python code (python `[filename]`, python) 9 | - Print: print() 10 | - Comments # 11 | - Variable assignment 12 | - Numbers (floats, integers) + math 13 | - Strings (", `'`, `""`") 14 | - Escaping stuff inside of strings 15 | - Variables inside strings 16 | - User input with input() 17 | 18 | *Now its time for you to put all of that knowledge to the test. Click the 'Submit Assignment' tab above and take the challenge!* 19 | 20 | **Good Luck <3!** 21 | -------------------------------------------------------------------------------- /Python-Projects/Functions/functions.py: -------------------------------------------------------------------------------- 1 | def greet(name): 2 | return f"Hey {name}!" 3 | 4 | def concatenate(word_one, word_two): 5 | return word_one + word_two 6 | 7 | def age_in_dog_years(age): 8 | result = age * 7 9 | return result 10 | 11 | print(greet('Mattan')) 12 | print(greet('Chris')) 13 | 14 | print(concatenate('Mattan', 'Griffel')) 15 | 16 | print(age_in_dog_years(28)) 17 | 18 | print(concatenate(word_two='Mattan', word_one='Griffel')) 19 | 20 | name = "Mattan" 21 | 22 | def print_different_name(): 23 | name = "Chris" 24 | print(name) 25 | 26 | print(name) 27 | print_different_name() 28 | print(name) 29 | 30 | 31 | def reverse(text): 32 | return text[::-1] 33 | 34 | def uppercase_and_reverse(text): 35 | return reverse(text.upper()) 36 | 37 | print(uppercase_and_reverse("banana")) # ANANAB -------------------------------------------------------------------------------- /Python-Projects/weather.py: -------------------------------------------------------------------------------- 1 | from darksky.api import DarkSky 2 | from darksky.types import languages, units, weather 3 | 4 | 5 | API_KEY = 'e2fea81b36c2588f1315c4ad2b721989' 6 | 7 | darksky = DarkSky(API_KEY) 8 | 9 | latitude = 42.3601 10 | longitude = -71.0589 11 | forecast = darksky.get_forecast( 12 | latitude, longitude, 13 | extend=False, # default `False` 14 | lang=languages.ENGLISH, # default `ENGLISH` 15 | units=units.AUTO, # default `auto` 16 | exclude=[weather.MINUTELY, weather.ALERTS] # default `[]` 17 | ) 18 | 19 | print(forecast.currently.temperature) 20 | 21 | forecast.latitude # 42.3601 22 | forecast.longitude # -71.0589 23 | forecast.timezone # timezone for coordinates. For exmaple: `America/New_York` 24 | 25 | forecast.currently # CurrentlyForecast. Can be finded at darksky/forecast.py 26 | forecast.minutely # MinutelyForecast. Can be finded at darksky/forecast.py 27 | forecast.hourly # HourlyForecast. Can be finded at darksky/forecast.py 28 | forecast.daily # DailyForecast. Can be finded at darksky/forecast.py 29 | forecast.alerts # [Alert]. Can be finded at darksky/forecast.py 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Python-Projects/Input/README.md: -------------------------------------------------------------------------------- 1 | # The input function 2 | 3 | *At some point in your programming career, you will write software that takes input from the user and processes it. This lesson covers how to do this. You will learn how to read and utilize user input. User input usually comes in the form of strings. Sometimes this isn't what your code needs and so we will show you how to cast this into an appropriate type.* 4 | 5 | *We're going to practice collecting inputs from users. Create a file called `input.py`.* 6 | 7 | *You can create variables which require the user to add information, the input, before printing the result. You can also create an interpolated string with the variables inside.* 8 | 9 | *The thing about user input is that it always comes in the form of a string. So, if you wanted to calculate a user's age in dog years, you need to convert the user input into a number you can multiply by seven.* 10 | 11 | *You could use the `int()` function to convert your string into an integer.* 12 | 13 | *So one of the easiest ways to fix this inside your script is to wrap `int()` your age input variable, like so: `int(input("How old are you?"))`. You could also theoretically do it for `age_in_dog_years =` as well.* -------------------------------------------------------------------------------- /Python-Projects/Math/README.md: -------------------------------------------------------------------------------- 1 | # Python math functions 2 | 3 | *One thing computers are great at is performing computations. In this lesson, we'll do some Math using Python. You'll learn how to use the common arithmetic operators (e.g. Addition, Subtraction, Multiplication, Division and Modulus) as well as the rules governing the order in which they are executed.* 4 | 5 | *Python is famous for it's ability to do amazing things with numbers and math. Check out the operations that you can do in the comments:* 6 | 7 | ```py 8 | # + plus 9 | # - minus 10 | # / divide 11 | # * times 12 | # ** exponentiation 13 | # % modulo 14 | # < less then 15 | # > greater then 16 | 17 | print("What is the answer to life, the universe, and everything?", int((40 + 30 - 7) * 2 / 3)) 18 | ``` 19 | 20 | *Remember that modulo basically divides one number by a number.* 21 | 22 | ## Let's practice some Python math 23 | 24 | ```py 25 | print("Is it true that 5 * 2 > 3 * 4?") 26 | 27 | print(5 * 2 > 3 * 4) 28 | 29 | print("What is 5 * 2?", 5 * 2) 30 | print("What is 3 * 4?", 3 * 4) 31 | ``` 32 | 33 | *Which gives this on the command line:* 34 | 35 | ```bash 36 | $ code python3 mymath.py 37 | What is the answer to life, the universe, and everything? 42 38 | Is it true that 5 * 2 > 3 * 4? 39 | False 40 | What is 5 * 2? 10 41 | What is 3 * 4? 12 42 | ``` 43 | 44 | *Remember that you can use parentheses in Python math the same way you would do in regular math.* -------------------------------------------------------------------------------- /Python-Projects/Python_Lists/lists.py: -------------------------------------------------------------------------------- 1 | the_count = [1, 2, 3, 4, 6] 2 | stocks = ["AAPL", "GOOG", "TSLA"] 3 | random_things = ["Puppies", 55, "Anthony Weiner", 1/2, ["Oh no", "A list inside a list"]] 4 | 5 | # this for-loop goes through a list 6 | for number in the_count: 7 | print("this is count", number) 8 | 9 | # same as above 10 | for stock in stocks: 11 | print("Stock ticker:", stock) 12 | 13 | # we can go through mixed lists too 14 | # I called it i (short for item) since I don't know what's in it 15 | for i in random_things: 16 | print("Here's a random thing:", i) 17 | 18 | # we can also build lists, first let's start with an empty one 19 | people = [] 20 | 21 | people.append("Mattan") 22 | people.append("Sarah") 23 | people.append("Chris") 24 | 25 | # now we can print them out too 26 | print(people) 27 | 28 | # and remove some 29 | people.remove("Sarah") 30 | print(people) 31 | 32 | for person in people: 33 | print("Person is:", person) 34 | 35 | # Challenge: Print out the square of the numbers 1 to 10 36 | for number in range(1, 11): 37 | print(number, "squared is", number * number) 38 | 39 | # here's how you access elements of a list 40 | animals = ['bear', 'tiger', 'penguin', 'zebra'] 41 | first_animal = animals[0] 42 | print(first_animal) 43 | third_animal = animals[2] 44 | print(third_animal) 45 | 46 | print("There are this many things:", len(random_things)) 47 | print("things is a:", type(random_things)) 48 | 49 | another_list = random_things[-1] 50 | print(another_list) 51 | print(type(another_list)) -------------------------------------------------------------------------------- /Python-Projects/Dictionary/dictionaries.py: -------------------------------------------------------------------------------- 1 | # states = ['NY', 'PA', 'CA'] 2 | # states = ['New York', 'Pennsylvania', 'California'] 3 | # states = ['New York', 'NY', 'Pennsylvania', 'PA', 'California', 'CA'] 4 | 5 | states = {'NY': 'New York', 'PA': 'Pennsylvania', 'CA': 'California'} 6 | 7 | print(states['NY']) 8 | 9 | # print(states['FL']) 10 | 11 | people = ["Mattan", "Chris"] 12 | # print(people[2]) 13 | 14 | print(type(states)) 15 | print(type(people)) 16 | 17 | print(states.get('FL', 'Not found')) 18 | print(states.get('NY', 'Not found')) 19 | 20 | print(states.keys()) 21 | print(states.values()) 22 | 23 | states['FL'] = 'Florida' 24 | print(states) 25 | 26 | # user = ['Mattan', 70, 10.5, 'Brown', 'Brown'] 27 | user = {'name': 'Mattan', 'height': 70, 'shoe size': 10.5, 'hair': 'Brown', 'eyes': 'Brown'} 28 | 29 | blog_post = {'title': '11 Sexy Uses for Dictionaries', 'body': 'Blah blah blah...'} 30 | 31 | print(user['name']) 32 | print(blog_post['title']) 33 | 34 | # Dictionaries and Lists can be inside of each other 35 | 36 | animal_sounds = { 37 | "cat": ["meow", "purr"], 38 | "dog": ["woof", "bark"], 39 | "fox": [] 40 | } 41 | 42 | mattan = {'name': 'Mattan', 'height': 70, 'shoe size': 10.5, 'hair': 'Brown', 'eyes': 'Brown'} 43 | chris = {'name': 'Chris', 'height': 68, 'shoe size': 10, 'hair': 'Brown', 'eyes': 'Brown'} 44 | sarah = {'name': 'Sarah', 'height': 72, 'shoe size': 8, 'hair': 'Brown', 'eyes': 'Brown'} 45 | 46 | people = [mattan, chris, sarah] 47 | 48 | print(people) 49 | 50 | for person in people: 51 | print(person.get('height')) 52 | 53 | 54 | -------------------------------------------------------------------------------- /Python-Projects/Variables/README.md: -------------------------------------------------------------------------------- 1 | # What are variables in Python? 2 | 3 | *Variables are used to label and store data that can be referenced and manipulated by your code. You have already worked with variables in the code you've written so far. This lesson will dive deeper into variables. You'll learn the rules governing the naming of variables as well as some recommended industry conventions to follow.* 4 | 5 | 6 | *I bet you already understand variables. Take a look at this basic math:* 7 | 8 | ```py 9 | a = 1 10 | b = 2 11 | c = a + b 12 | c = ? 13 | ``` 14 | 15 | *What is c? If you said c = 3 than your right.* 16 | 17 | - a, b, and c are variables. 18 | 19 | *Variables are just nicknames for things in your code. They are like boxes you can put things in and take them out of.* 20 | 21 | *Create a file called **variables.py**:* 22 | 23 | ```py 24 | # Variables are just nicknames 25 | # there plain, lowercase words 26 | # examples: x, y, banana, phone_a_quail 27 | 28 | name = "Mattan Griffel" 29 | orphan_fee = 200 30 | teddy_bear_fee = 121.80 31 | 32 | total = orphan_fee + teddy_bear_fee 33 | 34 | print(name, "the total will be", total) 35 | ``` 36 | 37 | > Tip: Vs code will suggest variables for you to fill in, and if you hit Tab, it will auto-complete them. 38 | 39 | - When you run the file: 40 | 41 | ```bash 42 | $ python variables.py 43 | Mattan Griffel the total will be 321.08 44 | ``` 45 | 46 | ## Variables in Python 47 | 48 | - Must start with a lowercase letter. 49 | - Can have letters, numbers, and underscores (but no spaces). 50 | - Should use underscores (instead of spaces). E.g. your_name. 51 | 52 | *When you define a variable, the variable name has to go on the left. This won't work:* 53 | 54 | ```py 55 | "Mattan Griffel" = name 56 | ``` 57 | -------------------------------------------------------------------------------- /Python-Homeworks/tip_submission_2.py: -------------------------------------------------------------------------------- 1 | #Assignment 1 for One Month Pyhon 2 | 3 | import random 4 | 5 | #Input from server 6 | server_name = input("Hello Kick Ass Steak House servant, please enter your name.\n") 7 | sub_total = float(input(f"Thank you {server_name}, please enter the subtotal of the patron's meal without the dollar sign ($)\n")) 8 | rounded_subtotal = float(f"{sub_total:.2f} \n") 9 | 10 | server_passover = input(f"Great {server_name}. Now hit [ENTER] and pass the device to the patron\n") 11 | 12 | #Input from patron 13 | patron_name = input("We hope you enjoyed your meal at Kick Asss Steak House, can I please get your name?\n") 14 | 15 | tip_selection = int(input(f"Thank you {patron_name}. The subtotal for your meal is ${rounded_subtotal}.\n" 16 | "Please enter your tip percentage (15, 18, 20): \n" 17 | "15 - average service\n" 18 | "18 - good service\n" 19 | "20 - fantastic service\n")) 20 | 21 | #Convert inputs to manipulate mathematically 22 | converted_subtotal = float(rounded_subtotal) 23 | total = (converted_subtotal * ( 1 + tip_selection /100)) 24 | 25 | salutation = ["Thank you for visiting us", 26 | "We hope to see you again soon", 27 | "Have a safe drive home"] 28 | 29 | random_salutation = random.choice(salutation) 30 | 31 | #Final messsage for patron showing total with tip 32 | print(f"{random_salutation} {patron_name}.\n") 33 | print(f"Your total with tip is ${total:.2f} \n") 34 | 35 | thoughts = ["Man, what a cheapskate. Hope they don't come back!", 36 | "Interesting tip, looks like they're celebrating big tonight!", 37 | "That person just gave me their number. Going to give them a call after my shift for some - Netflix and Chill!"] 38 | 39 | #Bonus thoughts from waiters and waitress at Kick Ass Steak House 40 | random_thoughts = random.choice(thoughts) 41 | 42 | see_thoughts = input("BONUS: Hit [ENTER] to see what our waiters & waitresses really thought of their patrons\n") 43 | print(random_thoughts) 44 | -------------------------------------------------------------------------------- /Python-Projects/Happy-Hour/README.md: -------------------------------------------------------------------------------- 1 | *In this lesson, we go through the Python code that you just ran in the last lesson line by line to understand what it does. You'll be introduced to Python syntax, how to store data in variables as well as how to print out information to the screen.* 2 | 3 | # Reading the Python Code Step by Step 4 | 5 | *Here's a step-by-step breakdown of our Python code.* 6 | 7 | ## 1. Top of the file 8 | 9 | ```py 10 | import random 11 | ``` 12 | 13 | *This imports other code. A library called 'random' that later allows us to pick out a random place or random person from our lists.* 14 | 15 | ## 2. Lists of Places & People 16 | 17 | ```py 18 | Places = ["MacDo", 19 | "LCW", 20 | "Marjan", 21 | "Picsin", 22 | "Burger King", 23 | "Hamam"] 24 | 25 | people = ["Ali", 26 | "Hamza", 27 | "Hassan Sensei", 28 | "Salma", 29 | "Ghelo", 30 | "Sokky" 31 | "Robi", 32 | "Oummy"] 33 | ``` 34 | 35 | *These are lists of places and people. They are going to be pulled into...* 36 | 37 | ## 3. Pick a random place and a random person 38 | 39 | ```py 40 | random_place = random.choice(Places) 41 | random_person_one = random.choice(people) 42 | ``` 43 | 44 | *This is where our script picks a random place and a random person.* 45 | 46 | ## 4. Print out the results 47 | 48 | ```py 49 | print(f"How about you go to {random_place} with {random_person_one} 50 | ``` 51 | 52 | *This line prints out the random place and random person.* 53 | 54 | *The best way to learn to code is by coding. In this lesson, you will dive into your first programming challenge. Don't be scared, let's dive in together! In the next lesson, we’ll review the solution (no peeking just yet).* 55 | 56 | # Happy Hour Challenges 57 | 58 | - I misspelled Hassan Sensei's name. Fix the typo. 59 | - Add another person to the list of people. 60 | - Change the script so it prints out three random people instead of one. (ex. How about you go to Lion's Head Tavern with Mattan and Chris?) 61 | -------------------------------------------------------------------------------- /Python-Projects/FizzBuzz_Challenge/README.md: -------------------------------------------------------------------------------- 1 | # The Famous Fizzbuzz Challenge 2 | 3 | *Challenge time! You are going to use what you've learned so far to solve the famous FizzBuzz Coding Challenge. The challenge is one of the most common coding interview questions.* 4 | 5 | **Here's the FizzBuzz challenge.** 6 | 7 | - Create a new file called `fizzbuzz.py`: 8 | 9 | ```py 10 | # Write a program that prints the numbers from 1 to 100. 11 | # But for multiples of three print "Fizz" instead of the number 12 | # and for the multiples of five print "Buzz". 13 | # For numbers that are multiples of both three and five print "FizzBuzz". 14 | 15 | # Tip: % (modulo) tells you what's left over when you divide one number by another 16 | # ex. number % 3 == 0 17 | 18 | ``` 19 | *Good luck!* 20 | 21 | 22 | 23 | # FizzBuzz Challenge: Solution 24 | 25 | *Here's the answer to FizzBuzz in Python. Hopefully, you gave the FizzBuzz challenge a try. Whether you got the solution or not, let's work through the logic together.* 26 | 27 | ## Step #1 28 | 29 | - First print out the numbers from 1 to 100: 30 | ```py 31 | for number in range(1,101): 32 | print(number) 33 | ``` 34 | 35 | ## Step #2 36 | 37 | - Print "Fizz" if the number is divisible by 3: 38 | 39 | ```py 40 | for number in range(1,101): 41 | if number % 3 == 0: 42 | print("Fizz") 43 | else: 44 | print(number) 45 | ``` 46 | 47 | ## Step #3 48 | 49 | - Print "Buzz" if the number is divisible by 5: 50 | 51 | ```py 52 | for number in range(1,101): 53 | if number % 3 == 0: 54 | print("Fizz") 55 | elif number % 5 == 0: 56 | print("Buzz") 57 | else: 58 | print(number) 59 | ``` 60 | 61 | ## Step #4 62 | 63 | - Print "FizzBuzz" if the number is divisible by 3 and 5: 64 | 65 | ```py 66 | for number in range(1,101): 67 | if number % 3 == 0 and number % 5 == 0: 68 | print("FizzBuzz") 69 | elif number % 3 == 0: 70 | print("Fizz") 71 | elif number % 5 == 0: 72 | print("Buzz") 73 | else: 74 | print(number) 75 | ``` 76 | 77 | **(Note that this new condition `number % 3 == 0 and number % 5 == 0` has to go above the other two because otherwise the others run first.)** -------------------------------------------------------------------------------- /Python-Projects/Strings/README.md: -------------------------------------------------------------------------------- 1 | *In programming, a string is a sequence of characters. They are usually used to store data in text form. Here, we explore the string format in Python. We see how to create them as well as how to deal with strings that contain special characters through what is referred to as Escaping. I'll also introduce you to Kanye West's "greatest pain."* 2 | 3 | - Strings are text surrounded by quotes (single, double, or triple) quotes. 4 | 5 | ```py 6 | # Strings are text surrounded by quotes 7 | # Both single (') or double (") or triple (""") quotes are used 8 | # examples: "dinosaurs", '2112', "I'm lovin' it!" 9 | ``` 10 | 11 | > Here's another example using a variable: 12 | 13 | ```py 14 | kanye_quote = "my greatest pain in live is that I will never be able to see myself perform live" 15 | 16 | print("kanye_quote") 17 | ``` 18 | 19 | *The command line will print out the string without the quotes. The Kanye quote is long, but if you want to break it up into multiple lines you can use triples-quotes `"""`:* 20 | 21 | ```py 22 | ... 23 | 24 | kanye_quote = """My greatest pain in life 25 | is that I will never be able 26 | to see myself perform live.""" 27 | 28 | ... 29 | ``` 30 | 31 | *But this will actually put newline breaks `(\n)` in between each line of the string. If you don't want those then you can avoid the newlines by putting a `\` at the end of each line, or simply by printing it with `print(kanye quote)` in the interpretive shell.* 32 | 33 | ## Escaping quotes in strings 34 | 35 | *One problem is that if you want to put single or double-quotes inside your string, Python will think you're trying to end your string.* 36 | 37 | *So if you want to use single or double-quotes in a string without closing it out, you have to "escape" it by putting a backslash (\) in front of it:* 38 | 39 | ```py 40 | ... 41 | 42 | hamilton_quote = "Well, the word got around, they said, \"This kid's insane, man\"" 43 | 44 | print(hamilton_quote) 45 | ``` 46 | 47 | *It never hurts to put a `\` in front of a quotation mark. You can also add newlines or tabs to strings with `\n` and `\t`.* 48 | 49 | *There are other characters you will need to escape. For example, in order to use a backslash in a string, you actually have to escape the backslash like this: `\\`.* 50 | 51 | *Triple quotes are another way to use either single or double quotations within a string. Like so:* 52 | 53 | ```py 54 | """Well, the word got around, they said, "This kid's insane, man""" 55 | ``` -------------------------------------------------------------------------------- /Python-Projects/Conditional Statements/README.md: -------------------------------------------------------------------------------- 1 | ## Introduction to Conditional Statements in Python 2 | 3 | *Conditional statements (also known as if/than statements) let you define specific times when something should happen. For example,"if" you say yes "than" I'll tell you a joke. Or on a website, "if" you are logged into the site, "than" I will send you a special announcement. In this lesson, I'll show you how to write conditionals in Python.* 4 | 5 | - Create a new file 6 | - Create a new file called if.py: 7 | 8 | ```py 9 | answer = input("Do you want to hear a joke? ") 10 | 11 | if answer == "Yes": 12 | print("I'm against picketing, but I don't know how to show it.") 13 | # Mitch Hedberg (RIP) 14 | ``` 15 | 16 | - Running the file, we see our joke, or we don't. 17 | 18 | ```bash 19 | $ python if.py 20 | Do you want to hear a joke? Yes 21 | I'm against picketing, but I don't know how to show it. 22 | $ python if.py 23 | Do you want to hear a joke? No 24 | $ 25 | ``` 26 | 27 | ## How does == work in Python? 28 | 29 | *`==` checks to see whether two things are equal. It returns `True` if they are and `False` if they aren't.* 30 | 31 | ```bash 32 | $ python 33 | >>> "Yes" == "Yes" 34 | True 35 | >>> "No" == "Yes" 36 | False 37 | ``` 38 | 39 | *Remember that even though they look similar, `=` and `==` are very different.* 40 | 41 | ```bash 42 | $ python 43 | >>> answer = "Yes" 44 | >>> answer == "Yes" 45 | True 46 | >>> answer = "No" 47 | >>> answer == "Yes" 48 | False 49 | ``` 50 | 51 | *You can also use `!=` to check if two things are different:* 52 | 53 | ```bash 54 | >>> answer != "Blue" 55 | True 56 | >>> answer != "No" 57 | False 58 | ``` 59 | 60 | ## How does if work? 61 | 62 | *`if` will check to see if something is `True` and then run any indented code after (after the colon).* 63 | 64 | ```py 65 | if True: 66 | # Anything here will run 67 | ``` 68 | 69 | *And accordingly:* 70 | 71 | ```py 72 | if False: 73 | # This will never run 74 | ``` 75 | 76 | *In this lesson, we expand our knowledge of Python conditional statements by looking at ways of checking for more than one condition by using the if...else, if...elif...else and nested if conditional statements.* 77 | 78 | ## if, elif, and else 79 | 80 | - In `if.py`: 81 | 82 | ```py 83 | answer = input("Do you want to hear a joke? ") 84 | 85 | if answer == "Yes": 86 | print("I'm against picketing, but I don't know how to show it.") 87 | # Mitch Hedberg (RIP) 88 | elif answer == "No": 89 | print("Fine.") 90 | else: 91 | print("I don't understand.") 92 | ``` 93 | 94 | *`else` lets you say what code you want to run if the `if` part doesn't turn out to be true.* 95 | 96 | *You can also add another `if` condition below the `if` with `elif` (you can actually add as many `elifs `as you want).* -------------------------------------------------------------------------------- /Python-Projects/Hello-World/README.md: -------------------------------------------------------------------------------- 1 | # Python Print() Statement: How to Print with Examples 2 | 3 | In this tutorial, you will learn 4 | 5 | - How to Print a simple String in Python? 6 | - How to print blank lines 7 | - Print end command 8 | 9 | ## Python print() function 10 | 11 | *The print() function in Python is used to print a specified message on the screen. The print command in Python prints strings or objects which are converted to a string while printing on a screen.* 12 | 13 | Syntax: 14 | 15 | ```py 16 | print(object(s)) 17 | ``` 18 | 19 | ## How to Print a simple String in Python? 20 | 21 | *More often then not you require to Print strings in your coding construct.* 22 | 23 | *Here is how to print statement in Python 3:* 24 | 25 | > Example: 1 26 | 27 | *To print the Welcome to Guru99, use the Python print statement as follows:* 28 | 29 | ```py 30 | print ("Welcome to s-shemmee's Github") 31 | ``` 32 | 33 | > Output: 34 | 35 | ```py 36 | Welcome to s-shemmee's Github 37 | ``` 38 | 39 | *In Python 2, same example will look like* 40 | 41 | ```py 42 | print "Welcome to s-shemmee's Github" 43 | ``` 44 | 45 | >Example 2: 46 | 47 | If you want to print the name of five countries, you can write: 48 | 49 | ```py 50 | print("USA") 51 | print("Canada") 52 | print("Germany") 53 | print("France") 54 | print("Japan") 55 | ``` 56 | 57 | > Output: 58 | 59 | ```py 60 | USA 61 | Canada 62 | Germany 63 | France 64 | Japan 65 | ``` 66 | ## How to print blank lines 67 | 68 | *Sometimes you need to print one blank line in your Python program. Following is an example to perform this task using Python print format.* 69 | 70 | > Example: 71 | 72 | *Let us print 8 blank lines. You can type:* 73 | 74 | ```py 75 | print (8 * "\n") 76 | ``` 77 | 78 | *or:* 79 | 80 | ```py 81 | print ("\n\n\n\n\n\n\n\n\n") 82 | ``` 83 | 84 | > Here is the code 85 | 86 | ```py 87 | print ("Welcome to s-shemmee's Github") 88 | print (8 * "\n") 89 | print ("Welcome to s-shemmee's Github") 90 | ``` 91 | 92 | > Output 93 | 94 | ``` 95 | Welcome to s-shemmee's Github 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | Welcome to s-shemmee's Github 104 | ``` 105 | 106 | ## Print end command 107 | 108 | *By default, print function in Python ends with a newline. This function comes with a parameter called ‘end.’ The default value of this parameter is ‘\n,’ i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available in only in Python 3+* 109 | 110 | > Example 1: 111 | 112 | ```py 113 | print ("Welcome to", end = ' ') 114 | print ("s-shemmee's Github", end = '!') 115 | ``` 116 | 117 | > Output: 118 | 119 | ``` 120 | Welcome to s-shemmee's Github! 121 | ``` 122 | 123 | > Example 2: 124 | 125 | `#` ends the output with `@`. 126 | 127 | ```py 128 | print("Python" , end = '@') 129 | ``` 130 | 131 | > Output: 132 | 133 | ```py 134 | Python@ 135 | ``` -------------------------------------------------------------------------------- /Python-Homeworks/tip_submission_3.py: -------------------------------------------------------------------------------- 1 | # One Month Python Week 1 Assignment 2 | 3 | # This script takes an input from the user for a restaurant check in USD. 4 | # After a 1- to 2-sentence description of each tipping rate, 5 | # it provides a guide on how much a tip of 15%, 18%, and 20% would total. 6 | # It then prompts the user for the rate of tip they wish to leave. 7 | # Finally, it provides the bill amount, tip amount, and grand total. 8 | 9 | import os 10 | os.system('clear') # start with a blank screen 11 | 12 | ########### G A T H E R B A S I C I N F O ##################### 13 | 14 | name = input("What is your name? ") 15 | restaurant = input("What is the name of the restaurant? ") 16 | check = float((input("What is the total amount of the check, in U.S. Dollars (example: 18.29)? $"))) 17 | 18 | ########## C A L C U L A T I O N S F O R P A R T I ############## 19 | 20 | tip_amt_15 = float( check * 15 / 100 ) # calc 15% tip rate: display in Part I 21 | tip_amt_18 = float( check * 18 / 100 ) # calc 18% tip rate: display in Part I 22 | tip_amt_20 = float( check * 20 / 100 ) # calc 20% tip rate: display in Part I 23 | gt15 = float( check + tip_amt_15 ) # calc Grand Total: display in Part I - 15% 24 | gt18 = float( check + tip_amt_18 ) # calc Grand Total: display in Part I - 18% 25 | gt20 = float( check + tip_amt_20 ) # calc Grand Total: display in Part I - 20% 26 | 27 | #################### D I S P L A Y P A R T I ############################## 28 | 29 | print() 30 | print("===============================================================================") 31 | print(f" Okay, {name}, you say your check at {restaurant} was ${check:.2f}") 32 | print(" so you should decide at which rate you wish to tip.") 33 | print(" Read the following brief guidelines then select your tip rate.") 34 | print(" NOTE: you don't have to pick one of these...you can make your rate anything. ") 35 | print() 36 | print(" 15% - Server was slow to arrive, slow with drinks, generally unpleasant") 37 | print() 38 | print(" 18% - Server was average in arriving at the table, was average in") 39 | print(" getting out the drinks, forgot something on the order") 40 | print() 41 | print(" 20% - Server was quick in all aspects, knew the menu well, refilled") 42 | print( " drinks without being asked, suggested particular dishes, and") 43 | print(" offered dessert") 44 | print() 45 | print(" Tip & Grand Totals for suggested levels provided for your convenience:") 46 | print() 47 | print(" 15% 18% 20%") 48 | print(f" ${tip_amt_15:.2f} ${tip_amt_18:.2f} ${tip_amt_20:.2f} ") 49 | print(f" ${gt15:.2f} ${gt18:.2f} ${gt20:.2f} ") 50 | print() 51 | print("===============================================================================") 52 | print() 53 | 54 | rate = float(input("Enter your desired tip rate (example: 15): ")) 55 | 56 | tip = float(check * rate / 100) 57 | grand_total = float(check + tip) 58 | 59 | #################### D I S P L A Y P A R T II ############################## 60 | 61 | print() 62 | print(f"""{name}, your check amount for {restaurant} was ${check:.2f} 63 | and you generously selected {rate:.2f} percent as your tip rate. 64 | Your tip amount is ${tip:.2f} 65 | which makes your Grand Total ${grand_total:.2f}""") 66 | print() 67 | print() -------------------------------------------------------------------------------- /Python-Projects/Logical_Operators/README.md: -------------------------------------------------------------------------------- 1 | # Logic Operators 2 | 3 | *In this lesson, we look at Python logical operators. The most popular ones you need to know are: `and`, `or` ,` not`, `==`, `!=`, `>`, and `<`. You'll also learn how to determine if a value is either True or False.* 4 | 5 | *The most popular truth terms in Python are: `and`, `or` , `not`, `==`, `!=`, `>`, and `<`.* 6 | 7 | *There's also `in`, which is a way of putting strings or variables together. As in:* 8 | 9 | ```bash 10 | $ python 11 | >>> people = ["Mattan", "Chris", "Sarah"] 12 | >>> "Mattan" in people 13 | True 14 | ``` 15 | 16 | ## How Does the "or" Operator Work in Python? 17 | 18 | *In this lesson, we introduce the "or" logical operator. This operator returns True if at least one of the expressions it's evaluating return True, otherwise, it returns False. You will learn some rules regarding the order in which it evaluates expressions—knowing this could save you from some logical bugs in your code.* 19 | 20 | **The "or" operator** 21 | 22 | - In `if.py`: 23 | 24 | ```py 25 | answer = input("Do you want to hear a joke? ") 26 | 27 | if answer == "Yes" or answer == "yes": 28 | print("I'm against picketing, but I don't know how to show it.") 29 | # Mitch Hedberg (RIP) 30 | elif answer == "No" or answer == "no" : 31 | print("Fine.") 32 | else: 33 | print("I don't understand.") 34 | ``` 35 | 36 | ## Understanding "in" in Python 37 | 38 | *If you have several values and want to evaluate if a certain value is equal to any of the available values, you can either string together several comparison expressions with OR statements, or even better, you can place the values in a Python sequence—for instance, a list—and use the IN operator to check if your data is in the list. This makes the code succinct and more readable.* 39 | 40 | **The "in" operator** 41 | 42 | *So how do you cover all the different ways that a user could respond to an input? Well, you can put together a list, and then use in to pull responses from that list:* 43 | 44 | In the `if.py` type: 45 | 46 | ```py 47 | answer = input("Do you want to hear a joke? ") 48 | 49 | affirmative_responses = ["yes", "y"] 50 | negative_responses = ["no", "n"] 51 | 52 | if answer.lower() in affirmative_responses: 53 | print("I'm against picketing, but I don't know how to show it.") 54 | # Mitch Hedburg (RIP) 55 | elif answer.lower() in negative_responses: 56 | print("Fine.") 57 | else: 58 | print("I don't understand.") 59 | 60 | ``` 61 | 62 | ## Boolean Practice Challenge 63 | 64 | *Time to put your newfound knowledge of Python logical operators to the test. In this lesson, you will download a .py (Python) file containing a list of conditional tests that evaluate to either True or False.* 65 | 66 | Time for some [Boolean Practice](https://github.com/s-shemmee/Python-in-30-Days/blob/main/Projects/Logical_Operators/boolean_practice.py)! 67 | 68 | ## Boolean Practice Solutions 69 | 70 | *Did you work through the last challenge? If you didn't, we recommend you go back and work through it before proceeding. Practicing is the best way to learn coding (or anything else). If you worked through the challenge, watch this lesson for the solutions to each of the problems and see how you did!* 71 | 72 | Here's the full set of answers for our boolean logic problems. [Boolean Answers](https://github.com/s-shemmee/Python-in-30-Days/blob/main/Projects/Logical_Operators/boolean_practice_solutions.py) -------------------------------------------------------------------------------- /Python-Projects/notebook_intro.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Introduction to Jupyter (formerly known as IPython) Notebook" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## 1) Click HERE only once (so the blue bar shows up on the left)" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": { 20 | "collapsed": true 21 | }, 22 | "source": [ 23 | "## 2) Use your arrow keys to move up and down" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "## 3) Stop on this row and press enter – notice you're now editing the row" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## 4) Press shift + enter to execute the row" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## 5) Now press B to create a new cell below the cursor – or A for above." 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": { 55 | "collapsed": true 56 | }, 57 | "source": [ 58 | "## 6) Practice step 5 a few times" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "## 7) Press ESC and use your arrow keys to highlight one of the new empty cells you created" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## 8) Delete the empty cell by pressing d + d (be careful!)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## 9) Run the Python code below by highlighting the row and pressing shift + enter" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 1, 85 | "metadata": { 86 | "collapsed": false 87 | }, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "good job!\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "print(\"good job!\")" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "A few notes:\n", 106 | "\n", 107 | "- Rows can contain many different languages, today we're just using Python\n", 108 | "- We can also use Markdown in cells and display pictures, web sites, etc\n", 109 | "- When in doubt, press ESC once to exit editing mode and use your arrows, A, B, dd, etc" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "## 10) Finally, go to File > Download as > Python (.py) to save this as a Python file" 117 | ] 118 | } 119 | ], 120 | "metadata": { 121 | "kernelspec": { 122 | "display_name": "Python 3.10.5 64-bit", 123 | "language": "python", 124 | "name": "python3" 125 | }, 126 | "language_info": { 127 | "codemirror_mode": { 128 | "name": "ipython", 129 | "version": 3 130 | }, 131 | "file_extension": ".py", 132 | "mimetype": "text/x-python", 133 | "name": "python", 134 | "nbconvert_exporter": "python", 135 | "pygments_lexer": "ipython3", 136 | "version": "3.10.5" 137 | }, 138 | "vscode": { 139 | "interpreter": { 140 | "hash": "26de051ba29f2982a8de78e945f0abaf191376122a1563185a90213a26c5da77" 141 | } 142 | } 143 | }, 144 | "nbformat": 4, 145 | "nbformat_minor": 1 146 | } 147 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python 101 for Beginners: Comprehensive Guide to Python Programming 2 | 3 | Welcome to the Python 101 repository! This repository aims to provide beginners with a solid foundation in Python programming. Whether you're new to programming or have some experience with other languages, this repository offers resources and guidance to get you started with Python. 4 | 5 | ## Course Contents 6 | 7 | 1. [Python Setup](0-Python-Setup.md): This guide will walk you through the process of setting up Python on your computer. 8 | 2. [Python Syllabus](1-Python-Syllabus.md): Explore the syllabus of the course, which outlines the topics and concepts covered. 9 | 3. [Python Data Structure](2-Python-Data-Structure.md): Learn about essential data structures in Python, such as lists, tuples, dictionaries, and sets. 10 | 4. [Python Control Flow](3-Python-Control-Flow.md): Understand control flow statements in Python, including if-else statements, loops, and conditional statements. 11 | 5. [Python Functions and Modules](4-Python-Functions-Modules.md): Dive into functions and modules in Python for code organization and reusability. 12 | 6. [File Handling and Input/Output](5-Python-File-Handling.md): Learn how to handle files and perform input/output operations in Python. 13 | 7. [Object-Oriented Programming](6-Python-OOP.md): Explore the principles of object-oriented programming in Python, including classes, objects, and inheritance. 14 | 8. [Error Handling and Exceptions](7-Python-Error-Handling.md): Understand how to handle errors and exceptions in Python programs. 15 | 9. [Python Libraries and Packages](8-Python-Libraries.md): Discover popular Python libraries and packages for various applications, such as data analysis, visualization, and web development. 16 | 10. [Python Web Development](9-Python-Web-Development.md): Get an introduction to web development using Python frameworks like Flask and Django. 17 | 11. [Database Integration with Python](10-Python-Database.md): Learn how to connect and interact with databases using Python, including SQLite and MySQL. 18 | 12. [Introduction to Data Science with Python](11-Python-Data-Science.md): Explore the basics of data science and how Python is used for data analysis and machine learning. 19 | 13. [Python Best Practices and Coding Standards](12-Python-Best-Practices.md): Discover best practices and coding standards to write clean, efficient, and maintainable Python code. 20 | 14. [Testing and Debugging in Python](13-Python-Testing-Debugging.md): Learn techniques and tools for testing and debugging Python code effectively. 21 | 15. [Python Project Development and Deployment](14-Python-Project-Development.md): Understand the process of developing and deploying Python projects. 22 | 23 | ## Homeworks and Projects 24 | 25 | - [Python-Homeworks](/Python-Homeworks): This folder contains a collection of Python homework assignments for practice. 26 | - [Python-Projects](/Python-Projects): Explore various Python projects to apply your knowledge and strengthen your skills. 27 | 28 | ## Getting Started 29 | 30 | To get started with Python, follow the courses in the numerical order mentioned above. Each course provides a comprehensive introduction to the topic along with examples and exercises to reinforce your learning. 31 | 32 | Feel free to explore the homework assignments and projects for hands-on practice. These resources will help you apply your knowledge to real-world scenarios and build practical Python skills. 33 | 34 | ## Resources and Support 35 | 36 | - [Python Official Documentation](https://docs.python.org/): The official Python documentation is an excellent resource for in-depth explanations and references. 37 | - [Python Community](https://www.python.org/community/): Join the Python community to connect with other learners and professionals, ask questions, and seek support. 38 | 39 | *We hope this repository serves as a valuable resource on your Python learning journey. Remember, practice is key to mastering Python. Happy coding!* 40 | 41 | > By [@s-shemmee](https://www.github.com/s-shemmee) 42 | -------------------------------------------------------------------------------- /Python-Projects/Dictionary/README.md: -------------------------------------------------------------------------------- 1 | # Consult The Dictionary 2 | 3 | *In this lesson, we look at Python dictionaries. A dictionary is an unordered, changeable and indexed collection that doesn't allow for duplicate members. It is similar to a list, in that it is a collection of objects, but the main difference between the two is that a list is ordered while a dictionary isn't.* 4 | 5 | *We already have a lot of different data types, but dictionaries are super important in order to do a lot of really useful things in Python. Dictionaries are basically lists - but lists go in order. With dictionaries, we use can look up something using a special key (basically a string).* 6 | 7 | - Create a file called `dictionaries.py`. Inside, follow this syntax: 8 | 9 | ```py 10 | # states = ['NY', 'PA', 'CA'] 11 | # states = ['New York', 'Pennsylvania', 'California'] 12 | # states = ['New York', 'NY', 'Pennsylvania', 'PA', 'California', 'CA'] 13 | 14 | states = {'NY': 'New York', 'PA': 'Pennsylvania', 'CA': 'California'} 15 | ``` 16 | 17 | *Voila! You've just created a dictionary. **The key value pair** are the things on either side of the colon. Note that **the key** is the thing to the left of the colon, and it has to be a string. But the thing on the right is the **value**, and that can be any data type.* 18 | 19 | *This is the main difference between dictionaries and lists. You can access anything inside of a dictionary using the key (a string). With lists, you have to access things by number. Lists also guarantee they'll return in a particular order, and dictionaries do not. This makes them fast.* 20 | 21 | # Searching a dictionary 22 | 23 | *To pull out the value from a dictionary, we simply print the key.* 24 | 25 | *If you try to access something that isn't in the dictionary, you'll get a key error. And if you ever get confused about what something is - a dictionary or a list - you can always use the `type()` function.* 26 | 27 | *You can search for things in dictionaries using `.get()`. It lets you look something up without returning a key error.* 28 | 29 | *You're also able to get all the keys in a given dictionary by printing `.keys()`.* 30 | 31 | *Adding things to a dictionary is actually pretty easy. And that will set the key, even if it doesn't already exist.* 32 | 33 | *Dictionaries are super useful to specify the information. Compare the list, which is commented out, with the dictionary, which keeps track of Mattan's details in a much more robust way:* 34 | 35 | ```py 36 | # user = ['Mattan', 70, 10.5, 'Brown', 'Brown'] 37 | user = {'name': 'Mattan', 'height': 70, 'shoe size': 10.5, 'hair': 'Brown', 'eyes': 'Brown' 38 | ``` 39 | 40 | # You've Got A List In My Dictionary! 41 | 42 | *In this lesson, I'll show you how to iterate and access values in objects, as well as show you how to avoid errors.* 43 | 44 | ## Lists inside of dictionaries 45 | 46 | *Your gonna see lots of lists inside dictionaries and dictionaries inside lists. This can get kind of crazy but stick with me.* 47 | 48 | ```py 49 | animal_sounds = { 50 | 51 | "cat": ["meow", "purr"], 52 | 53 | "dog": ["woof", "bark"], 54 | 55 | "fox": [] 56 | 57 | } 58 | ``` 59 | 60 | - We can do this for users as well. 61 | 62 | ```py 63 | mattan = {'name': 'Mattan', 'height': 70, 'shoe size': 10.5, 'hair': 'Brown', 'eyes': 'Brown'} 64 | 65 | chris = {'name': 'Chris', 'height': 68, 'shoe size': 10, 'hair': 'Brown', 'eyes': 'Brown'} 66 | 67 | sarah = {'name': 'Sarah', 'height': 72, 'shoe size': 8, 'hair': 'Brown', 'eyes': 'Brown'} 68 | ``` 69 | 70 | ## Create a list 71 | 72 | - But now let's create a list: 73 | 74 | ```py 75 | people = [mattan, chris, sarah] 76 | 77 | print(people) 78 | ``` 79 | 80 | *Remember that these variables inside our list are now all dictionaries. If you print the list, you'll get all the dictionaries.* 81 | 82 | *If you wanted to just print out the height of each person, you can loop over the list people, and realize that they all have the same keys. So you could use `person['height']` to get their height.* 83 | 84 | ## Loops 85 | 86 | - The loop looks like this: 87 | 88 | ```py 89 | for person in people: 90 | 91 | print(person['height']) 92 | ``` 93 | 94 | *Note this only works because I know all the dictionaries have the 'height' key. A safer option might be:* 95 | 96 | ```py 97 | for person in people: 98 | 99 | print(person.get('height')) 100 | ``` -------------------------------------------------------------------------------- /Python-Projects/Python_Lists/README.md: -------------------------------------------------------------------------------- 1 | # Python Lists 2 | 3 | *A list in Python is a collection of data. Lists can hold numbers, strings, boolean values (1 or 0), and other data structures (for instance, a list of lists!).* 4 | 5 | ## Python lists 6 | 7 | *Lists are basically that. Lists of things.* 8 | 9 | - In `lists.py`: 10 | 11 | ``` 12 | the_count = [1, 2, 3, 4, 6] 13 | stocks = ["AAPL", "GOOG", "TSLA"] 14 | random_things = ["Puppies", 55, "Anthony Weiner", 1/2, ["Oh no", "A list inside a list"]] 15 | ``` 16 | 17 | *A list can have anything you want inside it: numbers, strings, even lists inside of lists. That last one is an example of nesting structure. And if that makes your head hurt, break it down into smaller pieces.* 18 | 19 | ## For Looping 20 | 21 | *In this lesson, I'll show you how to loop over the elements in a list. This might come in handy in situations where you need to perform certain operations on each item in a list.* 22 | 23 | *You can use the `for x in list` syntax to loop over a list. The x is your variable name for the thing in the list. So this:* 24 | 25 | ```py 26 | # this for-loop goes through a list 27 | for number in the_count: 28 | print("this is count", number) 29 | ``` 30 | 31 | - Returns this: 32 | 33 | ```bash 34 | One-Months-Mac-mini:python mattangriffel$ python lists.py 35 | this is count 1 36 | this is count 2 37 | this is count 3 38 | this is count 4 39 | this is count 5 40 | One-Months-Mac-mini:python mattangriffel$ 41 | ``` 42 | 43 | - You can also do this same thing with strings. 44 | 45 | *Note that in your `for x in list` statement, the list has to already exist, but the X is a new variable your creating. So, if we were to ask `for i in random_list print ("Here's a random thing:", i)` then it would return everything in random_list, including the list nested inside random_list!* 46 | 47 | ## Removing Elements from a List 48 | 49 | *Here's your next challenge: print out the squares of the numbers 1-10. If you need help, I'd suggest you learn how to use the following in Python: insert(), pop(), clear() and del.* 50 | 51 | ## Append and remove 52 | 53 | *You can add things to a list with the `append()` function, and remove things from a list with the `remove()` function.* 54 | 55 | ```py 56 | # we can also build lists, first let's start with an empty one 57 | people = [] 58 | 59 | people.append("Mattan") 60 | people.append("Sarah") 61 | people.append("Chris") 62 | 63 | # now we can print them out too 64 | print(people) 65 | 66 | # and remove some 67 | people.remove("Sarah") 68 | print(people) 69 | ``` 70 | 71 | - This means that now when we use a for x in list function, we can set up like this: 72 | 73 | ```py 74 | for person in people: 75 | print("Person is:", person) 76 | ``` 77 | 78 | - And it will display our two people remaining in the list. 79 | 80 | ## Challenge 81 | 82 | **Here's a challenge:** print out the squares of the numbers 1-10. 83 | 84 | ## Home On The Python Range 85 | 86 | *In this lesson, I'll show you how we can use a range function instead of a list. In Python, a range will give you a sequence of numbers that are between two provided values: a lower limit and an upper limit. The sequence starts at the lower limit and goes up to, but doesn't include the upper limit.* 87 | 88 | *So now that you've had a chance to try it out yourself, let's look over how to print out a list of all the squares of each number from 1-10. You can do it by creating a list, like this:* 89 | 90 | ```py 91 | # Challenge: Print out the square of the numbers 1 to 10 92 | for number in range(1,2,3,4,5,6,7,8,9,10): 93 | print(number, "squared is", number * number) 94 | ``` 95 | 96 | *But in our quest to always keep our code as short and as clean as possible, let's look for another way to perform the same function. And in fact, there is: ranges.* 97 | 98 | ## Ranges 99 | 100 | *You can also use loops to do something a certain number of times with the range() function. It looks like this:* 101 | 102 | ```py 103 | # Challenge: Print out the square of the numbers 1 to 10 104 | for number in range(1,10): 105 | print(number, "squared is", number * number) 106 | ``` 107 | 108 | - And comes out on the terminal like so: 109 | 110 | ```bash 111 | $ python loops.py 112 | ... 113 | 1 squared is 1 114 | 2 squared is 4 115 | 3 squared is 9 116 | 4 squared is 16 117 | 5 squared is 25 118 | 6 squared is 36 119 | 7 squared is 49 120 | 8 squared is 64 121 | 9 squared is 81 122 | 10 squared is 100 123 | ``` 124 | 125 | **Note:** *Ranges start at the first number and go up to (but don't include) the second number. So if you want to do something 10 times, you have to use range(1,11).* 126 | 127 | ## How to Access Data in a List 128 | 129 | *Here, we look at ways we can access list items as well as ways we can get other useful information about a list and its items. You will find out how to access individual items inside a list using an index (sequentially as well as in reverse order), and how to find the "length" of a list.* 130 | 131 | - You can pull out parts of a list using `[]` after the name of the list, like this: 132 | 133 | ```py 134 | # here's how you access elements of a list 135 | animals = ['bear', 'tiger', 'penguin', 'zebra'] 136 | first_animal = animals[0] 137 | print(first_animal) 138 | third_animal = animals[2] 139 | print(third_animal) 140 | ``` 141 | 142 | - You can also find the length of a list with `len()` 143 | 144 | ```py 145 | print("They're are this many things:", len(random_things)) 146 | ``` 147 | 148 | **Note two things:** 149 | 150 | - The position of things in a list starts at 0, so to get the first thing you do `[0]`. 151 | Y- ou can go backwards through the list using negative numbers. The last thing in a list is always `[-1]`. 152 | 153 | *There's also the function `type()` which will tell you what kind of thing anything is.* 154 | 155 | *Now, when you're pulling things out of a list, you can also go backwards. So if you were to type `another_list = random_things[-1]`, then you'd get the list at the very end of our list of random things.* -------------------------------------------------------------------------------- /1-Python-Syllabus.md: -------------------------------------------------------------------------------- 1 | # Python Variables: How to Define/Declare String Variable Types 2 | 3 | ## What is a Variable in Python? 4 | 5 | *A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing.* 6 | 7 | ## Python Variable Types 8 | 9 | *Every value in Python has a datatype. Different data types in Python are Numbers, List, Tuple, Strings, Dictionary, etc. Variables in Python can be declared by any name or even alphabets like a, aa, abc, etc.* 10 | 11 | *In this tutorial, we will learn,* 12 | 13 | - How to Declare and use a Variable 14 | - Re-declare a Variable 15 | - Concatenate Variables 16 | - Local & Global Variables 17 | - Delete a variable 18 | 19 | ## How to Declare and use a Variable 20 | 21 | *Let see an example. We will define variable in Python and declare it as `“a”` and print it.* 22 | 23 | ```py 24 | a = 100 25 | print (a) 26 | ``` 27 | 28 | > Output 29 | 30 | ```py 31 | 100 32 | ``` 33 | 34 | ## Re-declare a Variable 35 | 36 | *You can re-declare Python variables even after you have declared once.* 37 | 38 | *Here we have Python declare variable initialized to a=0.* 39 | 40 | *Later, we re-assign the variable a to value “shemmee”* 41 | 42 | ```py 43 | # Declare a variable and initialize it 44 | a = 0 45 | 46 | # Re-declaring the variable works 47 | 48 | a = 'shemmee' 49 | 50 | ``` 51 | 52 | > Output 53 | 54 | ```py 55 | 0 56 | shemmee 57 | ``` 58 | 59 | > Python 2 Example 60 | 61 | ```py 62 | # Declare a variable and initialize it 63 | f = 0 64 | print f 65 | # re-declaring the variable works 66 | f = 'shemmee' 67 | print f 68 | ``` 69 | 70 | > Python 3 Example 71 | 72 | ```py 73 | # Declare a variable and initialize it 74 | f = 0 75 | print(f) 76 | # re-declaring the variable works 77 | f = 'shemmee' 78 | print(f) 79 | ``` 80 | 81 | ## Python String Concatenation and Variable 82 | 83 | *Let’s see whether you can concatenate different data types like string and number together. For example, we will concatenate “shemmee” with the number “21”.* 84 | 85 | *Unlike Java, which concatenates number with string without declaring number as string, while declaring variables in Python requires declaring the number as string otherwise it will show a TypeError* 86 | 87 | - For the following code, you will get undefined output 88 | 89 | ```py 90 | a = "shemmee" 91 | b = 21 92 | print a+b 93 | ``` 94 | 95 | - Once the integer is declared as string, it can concatenate both `“shemmee”` + `str(“21”)`= `“shemmee21”` in the output. 96 | 97 | ```py 98 | a="shemmee" 99 | b = 21 100 | print(a+str(b)) 101 | ``` 102 | 103 | ## Python Variable Types: Local & Global 104 | 105 | *There are two types of variables in Python, Global variable and Local variable. When you want to use the same variable for rest of your program or module you declare it as a global variable, while if you want to use the variable in a specific function or method, you use a local variable while Python variable declaration.* 106 | 107 | *Let’s understand this Python variable types with the difference between local and global variables in the below program.* 108 | 109 | - Let us define variable in Python where the variable “f” is global in scope and is assigned value 101 which is printed in output 110 | 111 | - Variable f is again declared in function and assumes local scope. It is assigned value “I am learning Python.” which is printed out as an output. This Python declare variable is different from the global variable “f” defined earlier 112 | 113 | - Once the function call is over, the local variable f is destroyed. At line 12, when we again, print the value of “f” is it displays the value of global variable f=101 114 | 115 | ```py 116 | # Declare a variable and initialize it aka Global variable 117 | f = 101 118 | print(f) 119 | 120 | # Local variable in function 121 | def someFunction(); 122 | f = 'i am learning Python' 123 | print(f) 124 | 125 | someFunction() 126 | 127 | print(f) 128 | ``` 129 | > Output: 130 | 131 | ```py 132 | 101 133 | i am learning Python 134 | 101 135 | ``` 136 | 137 | *While Python variable declaration using the keyword **global**, you can reference the global variable inside a function.* 138 | 139 | - Variable “f” is **global** in scope and is assigned value 101 which is printed in output 140 | 141 | - Variable f is declared using the keyword **global**. This is **NOT** a **local variable**, but the same **global** variable declared earlier. Hence when we print its value, the output is 101 142 | 143 | - We changed the value of “f” inside the function. Once the function call is over, the changed value of the variable “f” persists. At line 12, when we again, print the value of “f” is it displays the value “changing global variable” 144 | 145 | > Example 146 | 147 | ```py 148 | f = 101; 149 | print (f) 150 | # Global vs.local variables in functions 151 | def someFunction(): 152 | global f 153 | print (f) 154 | f = "changing global variable" 155 | someFunction() 156 | print (f) 157 | ``` 158 | 159 | > Output: 160 | 161 | ```py 162 | 101 163 | 101 164 | changing global variable 165 | ``` 166 | 167 | ## Delete a variable 168 | 169 | *You can also delete Python variables using the command del `“variable name”`.* 170 | 171 | *In the below example of Python delete variable, we deleted variable f, and when we proceed to print it, we get error **“variable name is not defined”** which means you have deleted the variable.* 172 | 173 | ```py 174 | f = 11; 175 | print(f) 176 | del f 177 | print(f) 178 | ``` 179 | 180 | ## Summary: 181 | 182 | - Variables are referred to “envelop” or “buckets” where information can be maintained and referenced. Like any other programming language Python also uses a variable to store the information. 183 | - Variables can be declared by any name or even alphabets like a, aa, abc, etc. 184 | - Variables can be re-declared even after you have declared them for once 185 | - Python constants can be understood as types of variables that hold the value which can not be changed. Usually Python constants are referenced from other files. Python define constant is declared in a new or separate file which contains functions, modules, etc. 186 | - Types of variables in Python or Python variable types : Local & Global 187 | - Declare local variable when you want to use it for current function 188 | - Declare Global variable when you want to use the same variable for rest of the program 189 | - To delete a variable, it uses keyword “del”. 190 | -------------------------------------------------------------------------------- /2-Python-Data-Structure.md: -------------------------------------------------------------------------------- 1 | # Python TUPLE – Pack, Unpack, Compare, Slicing, Delete, Key 2 | 3 | ## What is Tuple Matching in Python? 4 | 5 | **Tuple Matching in Python** *is a method of grouping the tuples by matching the second element in the tuples. It is achieved by using a dictionary by checking the second element in each tuple in python programming. However, we can make new tuples by taking portions of existing tuples.* 6 | 7 | - Tuple Syntax 8 | 9 | ```py 10 | Tup = ('Jan','feb','march') 11 | ``` 12 | 13 | - To write an empty tuple, you need to write as two parentheses containing nothing- 14 | 15 | ``` 16 | tup1 = (); 17 | ``` 18 | 19 | - For writing tuple for a single value, you need to include a comma, even though there is a single value. Also at the end you need to write semicolon as shown below. 20 | 21 | ```py 22 | Tup1 = (50,); 23 | ``` 24 | 25 | - Tuple indices begin at 0, and they can be concatenated, sliced and so on. 26 | 27 | > In this tutorial, we will learn 28 | 29 | - Packing and Unpacking 30 | - Comparing tuples 31 | - Using tuples as keys in dictionaries 32 | - Deleting Tuples 33 | - Slicing of Tuple 34 | - Built-in functions with Tuple 35 | - Advantages of tuple over list 36 | 37 | **Tuple Assignment** 38 | 39 | *Python has tuple assignment feature which enables you to assign more than one variable at a time. In here, we have assigned tuple 1 with the persons information like name, surname, birth year, etc. and another tuple 2 with the values in it like number (1,2,3,….,7).* 40 | 41 | > For Example: 42 | 43 | (name, surname, birth year, favorite movie and year, profession, birthplace) = Robert 44 | 45 | ```py 46 | tup1 = ('Robert', 'Carlos','1965','Terminator 1995', 'Actor','Florida'); 47 | tup2 = (1,2,3,4,5,6,7); 48 | print(tup1[0]) 49 | print(tup2[1:4]) 50 | ``` 51 | 52 | - Tuple 1 includes list of information of Robert 53 | - Tuple 2 includes list of numbers in it 54 | - We call the value for [0] in tuple and for tuple 2 we call the value between 1 and 4 55 | - Run the code- It gives name Robert for first tuple while for second tuple it gives number (2,3 and 4) 56 | 57 | ## Packing and Unpacking 58 | 59 | *In packing, we place value into a new tuple while in unpacking we extract those values back into variables.* 60 | ```py 61 | x = ("Guru99", 20, "Education") # tuple packing 62 | (company, emp, profile) = x # tuple unpacking 63 | print(company) 64 | print(emp) 65 | print(profile) 66 | ``` 67 | 68 | ## Comparing tuples 69 | 70 | A comparison operator in Python can work with tuples. 71 | 72 | The comparison starts with a first element of each tuple. If they do not compare to =,< or > then it proceed to the second element and so on. 73 | 74 | It starts with comparing the first element from each of the tuples 75 | 76 | > let’s study this with an example: 77 | 78 | #case 1 79 | ```py 80 | a=(5,6) 81 | b=(1,4) 82 | if (a>b):print("a is bigger") 83 | else: print("b is bigger") 84 | ``` 85 | 86 | #case 2 87 | ```py 88 | a=(5,6) 89 | b=(5,4) 90 | if (a>b):print("a is bigger") 91 | else: print ("b is bigger") 92 | ``` 93 | 94 | #case 3 95 | ```py 96 | a=(5,6) 97 | b=(6,4) 98 | if (a>b):print("a is bigger") 99 | else: print("b is bigger") 100 | ``` 101 | 102 | - **Case 1**: Comparison starts with a first element of each tuple. In this case 5>1, so the output a is bigger 103 | 104 | - **Case 2**: Comparison starts with a first element of each tuple. In this case 5>5 which is inconclusive. So it proceeds to the next element. 6>4, so the output a is bigger 105 | 106 | - **Case 3**: Comparison starts with a first element of each tuple. In this case 5>6 which is false. So it goes into the else block and prints “b is bigger.” 107 | 108 | ## Using tuples as keys in dictionaries 109 | 110 | *Since tuples are hashable, and list is not, we must use tuple as the key if we need to create a composite key to use in a dictionary.* 111 | 112 | > Example: 113 | 114 | *We would come across a composite key if we need to create a telephone directory that maps, first-name, last-name, pairs of telephone numbers, etc. Assuming that we have declared the variables as last and first number, we could write a dictionary assignment statement as shown below:* 115 | 116 | ``` 117 | directory[last,first] = number 118 | ``` 119 | 120 | *Inside the brackets, the expression is a tuple. We could use tuple assignment in a for loop to navigate this dictionary.* 121 | 122 | ``` 123 | for last, first in directory: 124 | ``` 125 | 126 | ``` 127 | print first, last, directory[last, first] 128 | ``` 129 | 130 | *This loop navigates the keys in the directory, which are tuples. It assigns the elements of each tuple to last and first and then prints the name and corresponding telephone number.* 131 | 132 | ## Tuples and dictionary 133 | 134 | *Dictionary can return the list of tuples by calling items, where each tuple is a key value pair.* 135 | 136 | ```py 137 | a = {'x':100, 'y':200} 138 | b = list(a.items()) 139 | print(b) 140 | ``` 141 | 142 | ## Deleting Tuples 143 | 144 | *Tuples are immutable and cannot be deleted. You cannot delete or remove items from a tuple. But deleting tuple entirely is possible by using the keyword* 145 | 146 | ``` 147 | del 148 | ``` 149 | 150 | ## Slicing of Tuple 151 | 152 | *To fetch specific sets of sub-elements from tuple or list, we use this unique function called slicing. Slicing is not only applicable to tuple but also for array and list.* 153 | 154 | ```py 155 | x = ("a", "b","c", "d", "e") 156 | print(x[2:4]) 157 | ``` 158 | 159 | - The output of this code will be (‘c’, ‘d’). 160 | 161 | > Here is the Python 2 Code for all above example 162 | 163 | ```py 164 | tup1 = ('Robert', 'Carlos','1965','Terminator 1995', 'Actor','Florida'); 165 | tup2 = (1,2,3,4,5,6,7); 166 | print tup1[0] 167 | print tup2[1:4] 168 | 169 | #Packing and Unpacking 170 | x = ("Guru99", 20, "Education") # tuple packing 171 | (company, emp, profile) = x # tuple unpacking 172 | print company 173 | print emp 174 | print profile 175 | 176 | #Comparing tuples 177 | #case 1 178 | a=(5,6) 179 | b=(1,4) 180 | if (a>b):print "a is bigger" 181 | else: print "b is bigger" 182 | 183 | #case 2 184 | a=(5,6) 185 | b=(5,4) 186 | if (a>b):print "a is bigger" 187 | else: print "b is bigger" 188 | 189 | #case 3 190 | a=(5,6) 191 | b=(6,4) 192 | if (a>b):print "a is bigger" 193 | else: print "b is bigger" 194 | 195 | #Tuples and dictionary 196 | a = {'x':100, 'y':200} 197 | b = a.items() 198 | print b 199 | 200 | #Slicing of Tuple 201 | x = ("a", "b","c", "d", "e") 202 | print x[2:4] 203 | ``` 204 | 205 | ## Built-in functions with Tuple 206 | 207 | *To perform different task, tuple allows you to use many built-in functions like all(), any(), enumerate(), max(), min(), sorted(), len(), tuple(), etc.* 208 | 209 | ## Advantages of tuple over list 210 | 211 | - Iterating through tuple is faster than with list, since tuples are immutable. 212 | - Tuples that consist of immutable elements can be used as key for dictionary, which is not possible with list 213 | - If you have data that is immutable, implementing it as tuple will guarantee that it remains write-protected 214 | 215 | # **Summary** 216 | 217 | *Python has tuple assignment feature which enables you to assign more than one variable at a time.* 218 | 219 | - Packing and Unpacking of Tuples 220 | - In packing, we place value into a new tuple while in unpacking we extract those values back into variables. 221 | - A comparison operator in Python can work with tuples. 222 | - Using tuples as keys in dictionaries 223 | - Tuples are hashable, and list are not 224 | - We must use tuple as the key if we need to create a composite key to use in a dictionary 225 | -Dictionary can return the list of tuples by calling items, where each tuple is a key value pair 226 | - Tuples are immutable and cannot be deleted. You cannot delete or remove items from a tuple. But deleting tuple entirely is possible by using the keyword “del” 227 | - To fetch specific sets of sub-elements from tuple or list, we use this unique function called slicing -------------------------------------------------------------------------------- /0-Python-Setup.md: -------------------------------------------------------------------------------- 1 | # Python cover 2 | 3 | # What is Python and why it is used? 4 | 5 | *Python is a general-purpose programming language that has wide application in various fields. In this documentation, we look at some areas in which Python is used, for example in web development, desktop app development, data science, building Internet of Things, creating distributed systems, etc.* 6 | 7 | *What can you do with Python? There are many, many cool things! We take a look, as well as cover what you will learn in this documentation.* 8 | 9 | # Features of Python 10 | 11 | ## Cross-platform 12 | 13 | *Python can be worked on multiple platforms such as Windows, Linux, etc.* 14 | 15 | ## Open Source 16 | 17 | *The reference implementation of Python i.e. CPython is Open Source.* 18 | 19 | ## Multiple Programming-paradigms 20 | 21 | *Programming Paradigms classify programming languages based on features, such as functional, procedural, object-oriented, declarative, etc. Python supports multiple programming paradigms such as object-oriented, functional programming, imperative, etc.* 22 | 23 | ## Fewer lines of code 24 | 25 | *A Python program uses lesser lines of code than C, C++, or Java, which makes it simpler* 26 | 27 | # How Should I Start Learning Python? 28 | 29 | *You might be wondering: How and why should I start learning Python? To help you answer that, we’ll look at various programming languages and compare a few popular ones with Python.* 30 | 31 | - So I'll give you three examples in PHP, Python, and Ruby. 32 | 33 | > Php 34 | 35 | ```php 36 | echo "Hello World"; 37 | ``` 38 | 39 | > Python 40 | 41 | ```python 42 | print ("Hello World") 43 | ``` 44 | 45 | > Ruby 46 | 47 | ```ruby 48 | puts "Hello World" 49 | ``` 50 | 51 | *Now if I run this code the end result I get is the text Hello World.* 52 | 53 | *So the outcome is exactly the same but the way that it looks is a little different like you might have noticed that the PHP has a semicolon at the end, that Python has that parenthesis around the Hello World, Ruby doesn't have either of those but the end result is exactly the same.* 54 | 55 | *You'll find out why Python is a useful tool to have under your belt whether you are learning your first language or looking to learn an additional one. You’ll find out why Python is especially a good language to learn for first-time developers.* 56 | 57 | # Python 2 vs Python 3 58 | 59 | *Python was created in 1991 by Guido Van Rossum. Guido is known as the Benevolent Dictator for Life because he is so awesome.* 60 | *And it's actually named after Monty Python, not the snake, as, you know, some people erroneously believe.* 61 | 62 | *Python 2 is legacy, Python 3 is the future and so we recommend learning the latter. The two versions share similarities, so if you learn Python 3, you will still be able to read and understand any legacy Python 2 code you might come upon.* 63 | 64 | *We look at the history of Python and explore the differences between Python 2 and Python 3. For the course, we use (and recommend) Python 3.* 65 | 66 | 67 | # Setup and Basic Python 68 | 69 | ## Installing Python and Setting Up Your Development Environment (IDE) 70 | 71 | *Before you can start coding with Python, you have to ensure that your computer is set up right. I'll take you through the process of installing Python on your MacOS, Windows or Linux OS via the Anaconda distribution. After that, you'll need to install a code editor. I use vs code and would suggest it for this course. But you can use any text editor you prefer.* 72 | 73 | ## Can We Take A Sanity Check? 74 | 75 | *"How do I know which version of Python I have?" is one of the most common questions I hear from students. In this section, I'll show you how to verify that you set up your development environment right. You'll test your Python installation and ensure that you have the right version of Python installed—version 3.0 or later*. 76 | 77 | **1. Install Vs Code** 78 | 79 | *Before we write our first line of Python code, you'll need to install a text editor (sometimes called an IDE). In this course, we'll be using vs code.* 80 | 81 | - Step 1 : 82 | 83 | - Download VS code from here Link. 84 | 85 | - Step 2 : 86 | 87 | - Download the Visual Studio Code installer for Windows. Once it is downloaded, run the installer (VSCodeUserSetup-{version}.exe). Then, run the file – it will only take a minute. 88 | 89 | 90 | 91 | - Accept the agreement and click `“next”`. 92 | 93 | 94 | 95 | - After accepting all the requests press finish button. By default, VS Code installs under: `"C:\users{username}\AppData\Local\Programs\Microsoft VS Code."` 96 | 97 | 98 | 99 | - If the installation is successful, you will see the following: 100 | 101 | 102 | 103 | 104 | **2. Install Python** 105 | 106 | *To download Python, go to Python’s official website.* 107 | 108 | *Now, keep the mouse cursor on the Downloads menu. The current version of Python i.e. Python 3.10 can now be seen,* 109 | 110 | 111 | 112 | *On clicking, the download begins,* 113 | 114 | 115 | 116 | *After the download completes, click on the arrow, and select Open to begin installing,* 117 | 118 | 119 | 120 | *Installation steps initiated. Select the checkbox `“Add Python 3.9 to PATH“`. After that, click Customize Installation as shown below:* 121 | 122 | 123 | 124 | *Now, you will reach the section Optional Features. This by default checks the “pip” package installer, test suite, py launcher, etc. Pip is used to install and manage Python packages.* 125 | 126 | *Keep the default and click `“Next“`:* 127 | 128 | 129 | 130 | *The Advanced Options section would be visible now. Select Install for all users. On selecting it will set the following installation path on its own. You can change the installation path by clicking Browse. If you want to keep the default path, click Install,* 131 | 132 | 133 | 134 | *Installation of all the components begins,* 135 | 136 | 137 | 138 | *After a few seconds, the installation completes as shown below. Click Close,* 139 | 140 | 141 | 142 | **3. Set Up Your Command Line** 143 | 144 | *The command line is where you run your code once you've written it, and its already installed by default on most computers.* 145 | 146 | *Now, verify whether we have successfully installed Python or not.* 147 | 148 | *Go to `START` -> type `CMD`, right-click `Open as Administrator`.* 149 | 150 | 151 | 152 | *The Command Prompt opens as shown below,* 153 | 154 | 155 | 156 | *Now, on typing the following command python –version on CMD, the following is visible, that means Python successfully installed on our Windows 10 OS:* 157 | 158 | 159 | 160 | 161 | **Common Issues Installing Python** 162 | 163 | - Make sure you restart your computer after running the Python installer. 164 | 165 | - Make sure you only type python in the prompt (no quotes, no spaces, no punctuation, nothing). 166 | 167 | - You may have to disable antivirus temporarily. 168 | 169 | - If you're on a work computer and it doesn't let you install Python or Sublime Text then you may need to contact your IT team and request permission. --------------------------------------------------------------------------------