From e7abdfdb073fe1d64050913f15844401c876b803 Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Sun, 26 Oct 2025 00:49:20 -0700 Subject: [PATCH 1/4] String slicing and indexing --- string slicing and indexing task .py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 string slicing and indexing task .py diff --git a/string slicing and indexing task .py b/string slicing and indexing task .py new file mode 100644 index 00000000..6ca079b9 --- /dev/null +++ b/string slicing and indexing task .py @@ -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)) From d068a515b2816dd621a962b95eeae36166765571 Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Mon, 27 Oct 2025 06:19:38 -0700 Subject: [PATCH 2/4] Add files via upload --- object oriented programing .py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 object oriented programing .py diff --git a/object oriented programing .py b/object oriented programing .py new file mode 100644 index 00000000..e4237761 --- /dev/null +++ b/object oriented programing .py @@ -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()}") From 7564bb249c98d0c2e9273700b41b502c794317c7 Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Mon, 27 Oct 2025 18:57:36 +0530 Subject: [PATCH 3/4] Add files via upload --- machine learning .py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 machine learning .py diff --git a/machine learning .py b/machine learning .py new file mode 100644 index 00000000..47971926 --- /dev/null +++ b/machine learning .py @@ -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]}") From d101f916f14d035bdc09116a03103368885907ef Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Fri, 31 Oct 2025 22:54:17 +0530 Subject: [PATCH 4/4] Add string slicing examples and user input handling --- String_Slicing/string_slicing.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 String_Slicing/string_slicing.py diff --git a/String_Slicing/string_slicing.py b/String_Slicing/string_slicing.py new file mode 100644 index 00000000..aab86697 --- /dev/null +++ b/String_Slicing/string_slicing.py @@ -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])