Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions String_Slicing/string_slicing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
text = "Hello, Python!"
print("Original string:", text)
print("Character at index 0:", text[0])
print("Character at index 7:", text[7])
print("Last character:", text[-1])
print("Second last character:", text[-2])
print("\nSlicing examples:")
print("Substring from index 0 to 5:", text[0:5])
print("Substring from index 7 to end:", text[7:])
print("Substring from start to index 5:", text[:5])
print("Whole string using slice:", text[:])
print("\nSlicing with step values:")
print("Every second character:", text[::2])
print("Reversed string:", text[::-1])
print("Substring with step of 3:", text[::3])
print("\n--- User Input Example ---")
user_string = input("Enter a string: ")
start = int(input("Enter start index: "))
end = int(input("Enter end index: "))
step = int(input("Enter step value: "))
print("Sliced string:", user_string[start:end:step])
29 changes: 29 additions & 0 deletions machine learning .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Advanced: Machine Learning Classifier Example
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score

# Load sample dataset
data = load_iris()
X, y = data.data, data.target

# Split into train and test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize and train the model
model = DecisionTreeClassifier()
model.fit(X_train, y_train)

# Make predictions
predictions = model.predict(X_test)

# Evaluate
accuracy = accuracy_score(y_test, predictions)
print(f"✅ Model trained successfully!")
print(f"Accuracy: {accuracy:.2f}")

# Predict for a single sample
sample = X_test[0].reshape(1, -1)
predicted_class = model.predict(sample)[0]
print(f"Example prediction → Class: {data.target_names[predicted_class]}")
24 changes: 24 additions & 0 deletions object oriented programing .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Task #32: Inheritance and Method Overriding Example

class Animal:
def __init__(self, name):
self.name = name

def sound(self):
return "Some generic animal sound"

# Dog inherits from Animal
class Dog(Animal):
def sound(self):
return "Woof! Woof!"

# Cat inherits from Animal
class Cat(Animal):
def sound(self):
return "Meow!"

# Demonstration
animals = [Dog("Buddy"), Cat("Kitty"), Animal("Creature")]

for animal in animals:
print(f"{animal.name} says: {animal.sound()}")
20 changes: 20 additions & 0 deletions string slicing and indexing task .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# String Slicing and Indexing Example

# Input a string from the user
text = input("Enter a string: ")

# Displaying first and last character
print("First character:", text[0])
print("Last character:", text[-1])

# Display a substring (from index 2 to 5)
print("Substring (index 2 to 5):", text[2:6])

# Reverse the string
print("Reversed string:", text[::-1])

# Print every second character
print("Every 2nd character:", text[::2])

# Length of the string
print("Length of the string:", len(text))