#π₯ Python OOP Example: Follow System Simulation
# Define a User class
class User:
# Initialize user with ID and username
def __init__(self, user_id, username):
self.id = user_id # Unique ID
self.username = username # User's name
self.followers = 0 # Starts with 0 followers
self.following = 0 # Starts with 0 following
# Define a follow method: this user follows another user
def follow(self, user):
user.followers += 1 # The other user gains a follower
self.following += 1 # This user follows someone
# Create two users
user1 = User("0.01", "Hosama")
user2 = User("0.02", "Angela")
# user1 follows user2
user1.follow(user2)
# Print current stats
print(user1.followers) # Output: 0 β Hosama has no followers
print(user1.following) # Output: 1 β Hosama is following Angela
print(user2.followers) # Output: 1 β Angela is followed by Hosama
print(user2.following) # Output: 0 β Angela is not following anyone
#π₯ Python OOP Example: Follow System Simulation
# Define a User class
class User:
# Initialize user with ID and username
def __init__(self, user_id, username):
self.id = user_id # Unique ID
self.username = username # User's name
self.followers = 0 # Starts with 0 followers
self.following = 0 # Starts with 0 following
# Define a follow method: this user follows another user
def follow(self, user):
user.followers += 1 # The other user gains a follower
self.following += 1 # This user follows someone
# Create two users
user1 = User("0.01", "Hosama")
user2 = User("0.02", "Angela")
# user1 follows user2
user1.follow(user2)
# Print current stats
print(user1.followers) # Output: 0 β Hosama has no followers
print(user1.following) # Output: 1 β Hosama is following Angela
print(user2.followers) # Output: 1 β Angela is followed by Hosama
print(user2.following) # Output: 0 β Angela is not following anyone
π₯ Python OOP: Simulate a Follow System Like Instagram/Telegram!
Using just one class and a few lines of code, we can simulate a real-world "Follow" feature. In this example:
β Each user has:
- An ID and username
- A follower count
- A following count
β The follow() method:
- Lets one user follow another
- Updates both users' counts accordingly
π§ Try making it more realistic: show mutual follows, unfollow feature, or a display method!
#python #oop #beginnercode #telegrambot #follow
π "Reading CSV Files with Python & Pandas!"
#TechWithHos #PythonTips #DataScience*
π *"Data is the new oil β and Python is the drill."*
In this snippet, we explore how to read and extract data from a CSV file using both Pythonβs built-in
π What this code does:
1. The first part (commented out) uses the
2. The second part uses Pandas to read the same file more efficiently β and directly accesses the "temp" column.
π Why use Pandas?
Pandas is a powerful Python library for data manipulation and analysis. It makes working with structured data super easy β whether itβs filtering rows, summarizing columns, or transforming tables.
π₯ With Pandas, a few lines of code can replace dozens!
Perfect for data science, machine learning, or just wrangling messy spreadsheets.
π‘ Follow @TechWithHos for more Python & tech tips like this!
\#Python #Pandas #CodeSnippet #CSV #LearnToCode #ProgrammingTips
#TechWithHos #PythonTips #DataScience*
π *"Data is the new oil β and Python is the drill."*
In this snippet, we explore how to read and extract data from a CSV file using both Pythonβs built-in
csv module and the powerful Pandas library.import csv
'''
with open("/Users/kvava/OneDrive/Desktop/002 weather-data.csv") as data_s:
h = data_s.readlines()
print(h)
with open("/Users/kvava/OneDrive/Desktop/002 weather-data.csv") as data_s:
data = csv.reader(data_s)
tempratures = []
for row in data:
if row[1] != "temp":
temp = int(row[1])
tempratures.append(temp)
print(tempratures)
'''
import pandas
data = pandas.read_csv("/Users/kvava/OneDrive/Desktop/002 weather-data.csv")
print(data["temp"])
π What this code does:
1. The first part (commented out) uses the
csv module to manually read temperature values from a CSV file.2. The second part uses Pandas to read the same file more efficiently β and directly accesses the "temp" column.
π Why use Pandas?
Pandas is a powerful Python library for data manipulation and analysis. It makes working with structured data super easy β whether itβs filtering rows, summarizing columns, or transforming tables.
π₯ With Pandas, a few lines of code can replace dozens!
Perfect for data science, machine learning, or just wrangling messy spreadsheets.
π‘ Follow @TechWithHos for more Python & tech tips like this!
\#Python #Pandas #CodeSnippet #CSV #LearnToCode #ProgrammingTips
π Python List Comprehension β Clean, Powerful, and Pythonic! π
List comprehensions make your code shorter, faster, and more readable. Whether you're transforming, filtering, or generating dataβthis tool is a must-know for any Pythonista!
Hereβs a quick showcase of how elegant Python can be π
β‘οΈ Why use list comprehensions?
β More readable than loops
β Great for data transformations
β Ideal for filtering and mapping
β Just look cooler π
π§ Try tweaking the conditions and expressionsβit's one of the fastest ways to learn Python.
\#Python #ListComprehension #CodeSnippet #PythonTips
List comprehensions make your code shorter, faster, and more readable. Whether you're transforming, filtering, or generating dataβthis tool is a must-know for any Pythonista!
Hereβs a quick showcase of how elegant Python can be π
# Add 1 to each item in a list
new_numbers = [item + 1 for item in numbers]
# Turn a string into a list of characters
name = "Angela"
new_list = [letter for letter in name]
# Square numbers from 1 to 4
new_double = [d * d for d in range(1, 5)]
# Double the numbers from 1 to 4
new_one = [s + s for s in range(1, 5)]
# Filter names with exactly 4 letters
names = ["Alex", "beth", "caroline", "Dave", "elias", "freddie"]
short_names = [sh for sh in names if len(sh) == 4]
# Capitalize names longer than 5 letters
capitalized = [ca.upper() for ca in names if len(ca) > 5]
β‘οΈ Why use list comprehensions?
β More readable than loops
β Great for data transformations
β Ideal for filtering and mapping
β Just look cooler π
π§ Try tweaking the conditions and expressionsβit's one of the fastest ways to learn Python.
\#Python #ListComprehension #CodeSnippet #PythonTips
# HsAd - Simple GUI using Tkinter
from tkinter import * # Import everything from tkinter (GUI library)
import turtle # Imported but not used in this program
# Create the main window
windows = Tk()
windows.title("My First GUI") # Set window title
windows.minsize(width=5, height=5) # Minimum window size
windows.config(padx=20, pady=20) # Add padding around the window
# ---------------- Label ----------------
# Create a label widget
my_label = Label()
my_label.grid(column=1, row=1) # Place label in grid at column 1, row 1
my_label.config(text="New Text") # Set default text
# ---------------- Button Function ----------------
# Function that runs when the button is clicked
def button_clicked():
input_text = input.get() # Get the text from input field
my_label.config(text=input_text) # Update label text with input
# ---------------- Buttons ----------------
# Create a button that calls 'button_clicked' function when clicked
button = Button(text="Click Me", command=button_clicked)
button.grid(column=2, row=2) # Place the button in grid
# Create a second button (no functionality added yet)
new_button = Button(text="Heyz Come Here")
new_button.grid(column=3, row=1)
# ---------------- Entry (Input Field) ----------------
# Create an input field for user to type in
input = Entry(width=10)
input.grid(column=4, row=3) # Place the input field in grid
# ---------------- Run the GUI ----------------
windows.mainloop() # Start the Tkinter event loop (keeps window open)
π₯οΈ Python Tkinter GUI - Beginner Project
Hey coders! π Here is Tech with hos
Here's a basic GUI (Graphical User Interface) created using Tkinter in Python. This project includes:
β A window with a title
β A label to display text
β An input box to type text
β A button that updates the label with your input
β Another button just for fun
π‘ When you type something in the box and click "Click me", the label updates with what you typed. Cool, right?
Perfect for beginners to understand how GUI elements like labels, buttons, and input fields work together. π»β¨
#Python #Tkinter #Beginner #GUI #CodeLearning
#Tech with hos
from tkinter import * # Import everything from tkinter (GUI library)
import turtle # Imported but not used in this program
# Create the main window
windows = Tk()
windows.title("My First GUI") # Set window title
windows.minsize(width=5, height=5) # Minimum window size
windows.config(padx=20, pady=20) # Add padding around the window
# ---------------- Label ----------------
# Create a label widget
my_label = Label()
my_label.grid(column=1, row=1) # Place label in grid at column 1, row 1
my_label.config(text="New Text") # Set default text
# ---------------- Button Function ----------------
# Function that runs when the button is clicked
def button_clicked():
input_text = input.get() # Get the text from input field
my_label.config(text=input_text) # Update label text with input
# ---------------- Buttons ----------------
# Create a button that calls 'button_clicked' function when clicked
button = Button(text="Click Me", command=button_clicked)
button.grid(column=2, row=2) # Place the button in grid
# Create a second button (no functionality added yet)
new_button = Button(text="Heyz Come Here")
new_button.grid(column=3, row=1)
# ---------------- Entry (Input Field) ----------------
# Create an input field for user to type in
input = Entry(width=10)
input.grid(column=4, row=3) # Place the input field in grid
# ---------------- Run the GUI ----------------
windows.mainloop() # Start the Tkinter event loop (keeps window open)
π₯οΈ Python Tkinter GUI - Beginner Project
Hey coders! π Here is Tech with hos
Here's a basic GUI (Graphical User Interface) created using Tkinter in Python. This project includes:
β A window with a title
β A label to display text
β An input box to type text
β A button that updates the label with your input
β Another button just for fun
π‘ When you type something in the box and click "Click me", the label updates with what you typed. Cool, right?
Perfect for beginners to understand how GUI elements like labels, buttons, and input fields work together. π»β¨
#Python #Tkinter #Beginner #GUI #CodeLearning
#Tech with hos
π Why Python for Competitive Programming?
Python isnβt just beginner-friendly β itβs a powerhouse for problem-solving. π‘
With clean syntax, rich libraries, and faster coding speed, you can focus on logic instead of long syntax battles.
It helps you turn ideas into solutions quickly β which is exactly what competitive programming is all about. β‘
π₯ Simple. Smart. Powerful. Thatβs Python.
#HosTech #Python #CompetitiveProgramming
Python isnβt just beginner-friendly β itβs a powerhouse for problem-solving. π‘
With clean syntax, rich libraries, and faster coding speed, you can focus on logic instead of long syntax battles.
It helps you turn ideas into solutions quickly β which is exactly what competitive programming is all about. β‘
π₯ Simple. Smart. Powerful. Thatβs Python.
#HosTech #Python #CompetitiveProgramming
β€1
Hey ... if youβre confused about learning AI , this might help.
Most people are not stuck because itβs hard. Theyβre stuck because they donβt know where to start.
So hereβs a simple starting path π
π» AI Coding
https://www.cursor.com/
https://github.com/features/copilot
β‘οΈ AI Agents
https://n8n.io/
https://www.youtube.com/@n8n-io
π Python + Data
https://www.python.org/
https://pandas.pydata.org/
https://www.kaggle.com/datasets
π Automation
https://www.make.com/
Donβt try everything. Pick ONE thing. Start small. Stay consistent.
And by the way β you can go with any of these skillsβ¦ it will help you leverage your main skill later.
What are you starting with?
π€ Prompt | π» Coding | β‘οΈ Agents | π Data | π Automation
#TechWithHos #LearnAI #Coding #StudentDeveloper #AItools #Python #CursorAI #n8n #TechSkills
Most people are not stuck because itβs hard. Theyβre stuck because they donβt know where to start.
So hereβs a simple starting path π
π» AI Coding
https://www.cursor.com/
https://github.com/features/copilot
β‘οΈ AI Agents
https://n8n.io/
https://www.youtube.com/@n8n-io
π Python + Data
https://www.python.org/
https://pandas.pydata.org/
https://www.kaggle.com/datasets
π Automation
https://www.make.com/
Donβt try everything. Pick ONE thing. Start small. Stay consistent.
And by the way β you can go with any of these skillsβ¦ it will help you leverage your main skill later.
What are you starting with?
π€ Prompt | π» Coding | β‘οΈ Agents | π Data | π Automation
#TechWithHos #LearnAI #Coding #StudentDeveloper #AItools #Python #CursorAI #n8n #TechSkills
β€7