├── .github └── workflows │ └── python-app.yml ├── 2FA.py ├── README.md ├── Top 10 Python algorithms ├── ai_model.py ├── calculating_compound_interest.py ├── matplotlib_example.py ├── pandas_example.py └── scikit_learn_train_machine_learning_model.py /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python 3 | 4 | name: Python application 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up Python 3.10 23 | uses: actions/setup-python@v3 24 | with: 25 | python-version: "3.10" 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install flake8 pytest 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | - name: Test with pytest 38 | run: | 39 | pytest 40 | -------------------------------------------------------------------------------- /2FA.py: -------------------------------------------------------------------------------- 1 | import pyotp 2 | 3 | def generate_secret_key(): 4 | secret_key = pyotp.random_base32() 5 | return secret_key 6 | 7 | # Generate an OTP for the user 8 | def generate_otp(secret_key): 9 | # Create a TOTP object with the secret key 10 | totp = pyotp.TOTP(secret_key) 11 | 12 | # Generate the OTP 13 | otp = totp.now() 14 | return otp 15 | 16 | # Verify the OTP entered by the user 17 | def verify_otp(secret_key, entered_otp): 18 | totp = pyotp.TOTP(secret_key) 19 | 20 | return totp.verify(entered_otp) 21 | 22 | 23 | secret_key = generate_secret_key() 24 | otp = generate_otp(secret_key) 25 | 26 | 27 | # Display the generated OTP 28 | print("Generated OTP:", otp) 29 | print() 30 | 31 | # Prompt the user to enter the OTP 32 | entered_otp = input("Enter the OTP: ") 33 | print() 34 | print(generate_secret_key()) 35 | 36 | if verify_otp(secret_key, entered_otp): 37 | print('OTP verification successful!') 38 | else: 39 | print('OTP verification failed!') -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Documentation Python Dev Society® code examples 2 | 3 | ![git_logo](https://user-images.githubusercontent.com/68993494/209866827-2e9629cc-3009-4e13-a7e5-202903b8702b.jpg) 4 | 5 | 🐍📚 Welcome to the Python Dev Society! 🐍📚 6 | 7 | At the Python Dev Society, our mission is to provide you with the most up-to-date news, tutorials, and resources for the Python programming language. Whether you're a beginner taking your first steps or an experienced Python developer, we have everything you need to enhance your skills and stay ahead of the curve. 🚀💻 8 | 9 | One exciting aspect of our community is our active GitHub repository, which is an integral part of our professional Facebook group. As a member, you gain access to a treasure trove of code examples and projects that showcase the versatility and power of Python. It's a fantastic opportunity to learn from real-world implementations and collaborate with fellow Python enthusiasts. 💡🤝 10 | 11 | Join us in the Python Dev Society and discover a wide range of content, including beginner's guides, advanced tutorials, news and updates, and engaging discussions in our community forum. Connect with like-minded individuals from across the globe, share your experiences, and get valuable insights from experts in the field. 🌍 12 | 13 | 🔗 [Link to Python Dev Soicety - official fan page 🌐](https://www.facebook.com/PythonDevSociety/) 14 | 15 | Whether you're just starting out with Python or aiming to deepen your knowledge and expertise, we have you covered. Explore our website to learn more, and remember to visit frequently for the latest updates and valuable insights that will fuel your Python journey. 🌟🔍 16 | 17 | Together, let's unlock the full potential of Python and embark on an exciting learning adventure in the Python Dev Society. 🐍🌟 18 | 19 | ## Python Code Examples: 20 | 21 | ➡ [Calculating compound interest](https://github.com/zahariev-webbersof/PythonDevSociety--code-examples/blob/main/calculating_compound_interest.py) 22 | 23 | ➡ [Using in ai in python](https://github.com/zahariev-webbersof/PythonDevSociety--code-examples/blob/main/ai_model.py) 24 | 25 | ➡ [Two-Factor Authentication (2FA)](https://github.com/zahariev-webbersof/PythonDevSociety--code-examples/blob/main/2FA.py) 26 | 27 | ➡ [Pandas DataFrame creation and filtering](https://github.com/zahariev-webbersof/PythonDevSociety--code-examples/blob/main/pandas_example.py) 28 | 29 | ➡ [Python script that uses the Matplotlib library to create an interesting visualization of a sine wave and a cosine wave](https://github.com/zahariev-webbersof/PythonDevSociety--code-examples/blob/main/matplotlib_example.py) 30 | ## Additional resources: 31 | ➡ [Python documentation](https://docs.python.org/3/) 32 | 33 | ➡ [Additional resources](#additional-resources) 34 | 35 | ➡ [Top 10 Pytohn algorithms](https://github.com/zahariev-webbersof/PythonDevSociety--code-examples/blob/main/Top%2010%20Python%20algorithms) 36 | 37 | -------------------------------------------------------------------------------- /Top 10 Python algorithms: -------------------------------------------------------------------------------- 1 | 🚀Hey Python Dev Society!🚀 2 | 3 | Today, we're diving into the 💫stellar world of Python algorithms!🐍🔥 4 | 5 | Here are the top 10 algorithms that Pythonistas swear by, each having its own unique strengths and applications. Let's get started! 6 | 7 | 1️⃣ **Linear Regression**:📈 The best friend of statisticians, it predicts an outcome based on a relationship between variables. Super helpful for forecasting! #LinearRegression 8 | 9 | 2️⃣ **Logistic Regression**: 🎯Need binary classification in Machine Learning? This is your go-to algorithm! #LogisticRegression 10 | 11 | 3️⃣ **K-Means Clustering**: 🏘️How about some group fun? This algorithm separates data into clusters based on similarity! #KMeans #Clustering 12 | 13 | 4️⃣ **Decision Trees**: 🌳Need some decisions? This ML algorithm uses a tree-like model to make predictions. #DecisionTrees 14 | 15 | 5️⃣ **Naive Bayes Classifier**: 🔮Predict the future! Naive Bayes is a super intuitive algorithm for classification problems. #NaiveBayes 16 | 17 | 6️⃣ **Support Vector Machines (SVM)**: 💡For complex classification problems, SVM creates hyperplanes to classify data. Pretty genius, huh? #SVM 18 | 19 | 7️⃣ **Random Forests**: 🌲🌲Take Decision Trees, put them in an ensemble and voila! You have a Random Forest. More trees, more accuracy! #RandomForests 20 | 21 | 8️⃣ **Principal Component Analysis (PCA)**: 💼Big data? No problem! PCA simplifies high-dimensionality data while keeping it's structure intact. #PCA 22 | 23 | 9️⃣ **Gradient Boosting**: 🚀Boost your ML model's performance! This algorithm turns weak learners into strong ones. #GradientBoosting 24 | 25 | 🔟 **Neural Networks**: 🧠Unleash the power of the human brain in your ML models. Great for pattern recognition! #NeuralNetworks 26 | 27 | So there you have it, folks! The top 10 algorithms that every Python developer should have in their arsenal.🎯💪 28 | 29 | Stay tuned for more exciting insights!🔥 30 | 31 | And remember - Keep Calm and Code Python!🐍✨ 32 | -------------------------------------------------------------------------------- /ai_model.py: -------------------------------------------------------------------------------- 1 | # Import necessary libraries 2 | import pandas as pd 3 | from sklearn.linear_model import LinearRegression 4 | 5 | # Load the data 6 | data = pd.read_csv("data.csv") 7 | 8 | # Split the data into input and output variables 9 | X = data.iloc[:, :-1].values 10 | y = data.iloc[:, -1].values 11 | 12 | # Train the model 13 | model = LinearRegression() 14 | model.fit(X, y) 15 | 16 | # Make predictions on new data 17 | new_data = [[5.1, 3.5, 1.4, 0.2]] 18 | prediction = model.predict(new_data) 19 | 20 | # Print the prediction 21 | print(prediction) 22 | -------------------------------------------------------------------------------- /calculating_compound_interest.py: -------------------------------------------------------------------------------- 1 | def compound_interest(principal, rate, time): 2 | amount = principal * (1 + rate/100) ** time 3 | return amount 4 | 5 | principal = 1000 6 | rate = 5 7 | time = 5 8 | 9 | future_value = compound_interest(principal, rate, time) 10 | print("Future value:", future_value) 11 | -------------------------------------------------------------------------------- /matplotlib_example.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | # Generate data 5 | x = np.linspace(0, 2 * np.pi, 100) 6 | y1 = np.sin(x) 7 | y2 = np.cos(x) 8 | 9 | # Create a figure and axis 10 | plt.figure(figsize=(8, 6)) 11 | plt.title("Sine and Cosine Waves") 12 | plt.xlabel("X-axis") 13 | plt.ylabel("Y-axis") 14 | 15 | # Plot the sine wave in blue and cosine wave in red 16 | plt.plot(x, y1, label="Sine Wave", color="blue") 17 | plt.plot(x, y2, label="Cosine Wave", color="red") 18 | 19 | # Add legend 20 | plt.legend() 21 | 22 | # Highlight data points where sine and cosine intersect 23 | intersection_points = np.where(np.isclose(y1, y2)) 24 | plt.scatter(x[intersection_points], y1[intersection_points], color="green", label="Intersection Points") 25 | 26 | # Annotate the intersection points 27 | for i in intersection_points[0]: 28 | plt.annotate(f'({x[i]:.2f}, {y1[i]:.2f})', (x[i], y1[i]), textcoords="offset points", xytext=(0,10), ha='center', fontsize=8) 29 | 30 | # Customize the plot appearance 31 | plt.grid() 32 | plt.axhline(0, color='black', linewidth=0.8) 33 | plt.axvline(0, color='black', linewidth=0.8) 34 | plt.xticks(np.arange(0, 2*np.pi+0.1, np.pi/2), ['0', '$\\frac{\pi}{2}$', '$\pi$', '$\\frac{3\pi}{2}$', '$2\pi$']) 35 | 36 | # Show the plot 37 | plt.tight_layout() 38 | plt.show() 39 | -------------------------------------------------------------------------------- /pandas_example.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | # Creating a simple DataFrame 4 | data = {'Name': ['John', 'Anna', 'Peter', 'Linda'], 5 | 'Age': [28, 24, 35, 32], 6 | 'City': ['New York', 'Paris', 'Berlin', 'London']} 7 | df = pd.DataFrame(data) 8 | 9 | # Display the DataFrame 10 | print(df) 11 | print() 12 | 13 | # Add a new column 14 | df['Profession'] = ['Engineer', 'Doctor', 'Architect', 'Scientist'] 15 | print(df) 16 | print() 17 | 18 | # Filter the DataFrame based on age 19 | filtered_df = df[df['Age'] > 30] 20 | print(filtered_df) 21 | print() -------------------------------------------------------------------------------- /scikit_learn_train_machine_learning_model.py: -------------------------------------------------------------------------------- 1 | from sklearn import datasets 2 | from sklearn.ensemble import RandomForestClassifier 3 | from sklearn.model_selection import train_test_split 4 | 5 | iris = datasets.load_iris() 6 | X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42) 7 | 8 | clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=42) 9 | clf.fit(X_train, y_train) 10 | 11 | accuracy = clf.score(X_test, y_test) 12 | print(f"Accuracy: {accuracy}") 13 | --------------------------------------------------------------------------------