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
4 changes: 2 additions & 2 deletions basics/03_control_flow/06_greet_names.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Write a program to greet all the person names stored in a list 'l' and which starts
with S.
l = ["Harry", "Soham", "Sachin", "Rahul","Harish","Hetbe","Rajesh","Harish Meheta"]"""
l = ["Harry", "Soham", "Sachin", "Rahul","Harish","Hetbe","rajesh","Harish Meheta"]"""


names_list = ["Harry", "Soham", "Sachin", "Rahul","Harish","Hetbe","Rajesh","Harish Meheta"]
names_list = ["Harry", "Soham", "Sachin", "Rahul","Harish","Hetbe","rajesh","Harish Meheta"]
for name in names_list:
if(name.startswith("H")):
print(f"Greet Sended to {name}")
2 changes: 1 addition & 1 deletion basics/05_data_structures/04_list_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ def remove_and_strip(string_list, word):
return cleaned_list


string_list = ["Ram","Shyam","Gyan",'Pyan',"Myan","an"]
string_list = ["ram","Shyam","Gyan",'Pyan',"Myan","an"]
print(remove_and_strip(string_list, "an"))
4 changes: 2 additions & 2 deletions basics/05_data_structures/11_tuple_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
print(empty_tuple) #Prints the Blank Tuple


tuple1 = ("Hello","12345",False,"Ram","Ram") #tuple1
tuple1 = ("Hello","12345",False,"ram","ram") #tuple1
tuple2 = (1222.22,False,24224.4224,"String") #tuple2
print(tuple1.count("Hello")) #--> Return number of occurrences of value.
print(tuple1.index("Ram")) #-->Return first index of value.
print(tuple1.index("ram")) #-->Return first index of value.
print(len(tuple1)) #-->Return the number of items in a container.
print(tuple1 + tuple2) #-->Concatenation of two tuples
6 changes: 3 additions & 3 deletions basics/05_data_structures/15_set_methods.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Set Methods Example

set1 = {1, 2, 3, 4, 5, False, True, "Aman", 23.23, "Rajesh", "Patel", "Sharma"}
set2 = {1, 2, 3, 4, 5, "Rajesh", "Patel", "ranjit"}
set1 = {1, 2, 3, 4, 5, False, True, "Aman", 23.23, "rajesh", "Patel", "Sharma"}
set2 = {1, 2, 3, 4, 5, "rajesh", "Patel", "ranjit"}
set3 = {462, 3297}
set4 = {"freefire", "enormous"}

# Adding and removing elements
set1.add("Ram chandra ") # Add single element
set1.add("ram chandra ") # Add single element
set1.clear() # Remove all elements
print(set1.copy()) # Create a copy

Expand Down
8 changes: 4 additions & 4 deletions basics/05_data_structures/16_dict_basics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Dictionary Methods Example

dictionary_data = {
"Ram": 100,
"ram": 100,
"Kiran": 90,
"Sneha": 99.999,
"String": 33.33,
"l1": [12, 22],
"t1": ("Ram", "Sita")
"t1": ("ram", "Sita")
}

print(dictionary_data.items()) # View all key-value pairs
Expand All @@ -15,9 +15,9 @@
print(dictionary_data.values()) # Get all values
print(dictionary_data.get("Rama")) # Safe access (returns None if key missing)

dictionary_data.update({"Ram": 33.333}) # Update existing key
dictionary_data.update({"ram": 33.333}) # Update existing key
print(dictionary_data.copy()) # Create a shallow copy
print(dictionary_data.pop("Ram")) # Remove key and return value
print(dictionary_data.pop("ram")) # Remove key and return value

# Create new dict from keys
print(dictionary_data.fromkeys({"Rakesh", "Prasant"}))
Expand Down
4 changes: 2 additions & 2 deletions basics/05_data_structures/17_dict_friends.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
shyam_language = input("Enter your Favourite Programming Language : ")
gita_language = input("Enter your Favourite Programming Language : ")
ritu_language = input("Enter your Favourite Programming Language : ")
friends_languages = {"Ram":None,"Shyam":None,"Gita":None,"Ritu":None}
friends_languages.update({'Ram':ram_language})
friends_languages = {"ram":None,"Shyam":None,"Gita":None,"Ritu":None}
friends_languages.update({'ram':ram_language})
friends_languages.update({'Shyam':shyam_language})
friends_languages.update({'Gita':gita_language})
friends_languages.update({'Ritu':ritu_language})
Expand Down
2 changes: 1 addition & 1 deletion basics/05_data_structures/19_enumerate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Before Using emumerate
items_list = ["Hello",23,False,True,45,"Ram"]
items_list = ["Hello",23,False,True,45,"ram"]
index = 0
for item in items_list:
print(f"The item number at index {index} is {item}")
Expand Down
2 changes: 1 addition & 1 deletion basics/06_strings/02_string_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
print(name.capitalize()) #Make the first letter of the word uppercase
print(name.count("good")) #Counts the given string
print(name.endswith("Boy")) #check that the given String ends with Boy or not
print(name.startswith("Ram")) #check that the given String Starts with Ram or not
print(name.startswith("ram")) #check that the given String Starts with ram or not
print(name.find("good")) #return the index of the first occurence of the given Str
print(name.index("good")) #return the index of the first occurence of the given Str
print(name.isalnum()) #check the given string is alpha-numeric or not
Expand Down
2 changes: 1 addition & 1 deletion basics/06_strings/03_string_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
template.format(p1,p2...)
'''

print("{} is a Good boy and {} is a Bad boy".format("Raghav","Rajesh"))
print("{} is a Good boy and {} is a Bad boy".format("Raghav","rajesh"))
print("{} is my friend and {} loves me alot".format("X","Y"))
34 changes: 17 additions & 17 deletions basics/08_oop/02_class_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ def __init__(self, choose, num):
self.choose = choose
self.num = num

def Square(self, Num):
self.Num = Num
Num = Num ** 2 # For Square
result = round(Num, 2)
def square(self, num):
self.num = num
num = num ** 2 # For Square
result = round(num, 2)
print(f"Here is Your Square: {result}")

def Cube(self, Num):
self.Num = Num
Num = Num ** 3 # For Cube
result = round(Num, 2)
def cube(self, num):
self.num = num
num = num ** 3 # For Cube
result = round(num, 2)
print(f"Here is Your Cube: {result}")

def SquareRoot(self, Num):
self.Num = Num
Num = Num ** 0.5 # For Square Root
result = round(Num, 2)
def square_root(self, num):
self.num = num
num = num ** 0.5 # For Square Root
result = round(num, 2)
print(f"Here is Your SquareRoot: {result}")

@staticmethod
def Wrong():
def wrong():
print("Wrong Number!")


Expand All @@ -35,10 +35,10 @@ def Wrong():
num = Calculator(choose, Number)

if choose == 1:
num.Square(Number)
num.square(Number)
elif choose == 2:
num.Cube(Number)
num.cube(Number)
elif choose == 3:
num.SquareRoot(Number)
num.square_root(Number)
else:
num.Wrong()
num.wrong()
28 changes: 14 additions & 14 deletions basics/08_oop/04_class_encapsulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ def __init__(self, name, level, health):
self._health = health # Private variable for health

@property
def Name(self):
def name(self):
return self._name

@property
def Level(self):
def level(self):
return self._level

@property
def Health(self):
def health(self):
return self._health

@Name.setter
def Name(self, value):
@name.setter
def name(self, value):
if value != "":
self._name = value
else:
print("Name Can't be Blank!")

@Level.setter
def Level(self, value):
@level.setter
def level(self, value):
if 1 <= value <= 50:
self._level = value
else:
print("Level Must be between 1 and 50")

@Health.setter
def Health(self, value):
@health.setter
def health(self, value):
if 0 <= value <= 100:
self._health = value
else:
Expand All @@ -59,12 +59,12 @@ def Health(self, value):
Adam = GameCharacter("Adam", 45, 98)

print("Output")
print(f"\tName: {Adam.Name}\n\tLevel: {Adam.Level}\n\tHealth: {Adam.Health}\n")
print(f"\tName: {Adam.name}\n\tLevel: {Adam.level}\n\tHealth: {Adam.health}\n")

print("Updated Output:\n")
# Trying to set invalid values
Adam.Name = ""
Adam.Level = -51
Adam.Health = -101
Adam.name = ""
Adam.level = -51
Adam.health = -101

print(f"\tName: {Adam.Name}\n\tLevel: {Adam.Level}\n\tHealth: {Adam.Health}\n")
print(f"\tName: {Adam.name}\n\tLevel: {Adam.level}\n\tHealth: {Adam.health}\n")
38 changes: 19 additions & 19 deletions basics/08_oop/08_oop_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ def __init__(self, power, health, speed): # Constructor to initialize object
self._speed = speed # Private variable for speed

@property
def Power(self): # Getter 1 for power
def power(self): # Getter 1 for power
return self._power

@property
def Health(self): # Getter 2 for health
def health(self): # Getter 2 for health
return self._health

@property
def Speed(self): # Getter 3 for speed
def speed(self): # Getter 3 for speed
return self._speed

@Speed.setter
def Speed(self, value): # Setter 1 for speed
@speed.setter
def speed(self, value): # Setter 1 for speed
if 0 < value < 100:
self._speed = value
else:
print("Values Must be between 0 and 100")

@Power.setter
def Power(self, value): # Setter 2 for power
@power.setter
def power(self, value): # Setter 2 for power
if 0 < value < 100:
self._power = value
else:
print("Values Must be between 0 and 100")

@Health.setter
def Health(self, value): # Setter 3 for health
@health.setter
def health(self, value): # Setter 3 for health
if 0 < value < 100:
self._health = value
else:
Expand All @@ -43,22 +43,22 @@ def Health(self, value): # Setter 3 for health
devil = Monster(12, 90, 34)

# Accessing values using getters (like variables)
print(f"Here is Your Health : {devil.Health} Power : {devil.Power} & Speed : {devil.Speed}\nUpdated Data")
print(f"Here is Your Health : {devil.health} Power : {devil.power} & Speed : {devil.speed}\nUpdated Data")

# Modifying values using setters (with validation)
devil.Speed = 90
devil.Health = 98
devil.Power = 89
devil.speed = 90
devil.health = 98
devil.power = 89

# Accessing updated values using getters
print(f"Here is Your Health : {devil.Health} Power : {devil.Power} & Speed : {devil.Speed}\n")
print(f"Here is Your Health : {devil.health} Power : {devil.power} & Speed : {devil.speed}\n")

devil = Monster(12,90,34)
print(f"Here is Your Health : {devil.Health} Power : {devil.Power} & Speed : {devil.Speed}\nUpdated Data")
devil.Speed = 90
devil.Health = 98
devil.Power = 89
print(f"Here is Your Health : {devil.Health} Power : {devil.Power} & Speed : {devil.Speed}\n")
print(f"Here is Your Health : {devil.health} Power : {devil.power} & Speed : {devil.speed}\nUpdated Data")
devil.speed = 90
devil.health = 98
devil.power = 89
print(f"Here is Your Health : {devil.health} Power : {devil.power} & Speed : {devil.speed}\n")



Expand Down
6 changes: 3 additions & 3 deletions basics/08_oop/09_inheritance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
class LivingThings:
isLive = True

def CanHearSound(self):
def can_hear_sound(self):
print("We Can Hear Sound")


class HumanBeings(LivingThings): # Single Level Inheritance
def Intelligent(self):
def intelligent(self):
print("Most Intelligent!")


class Animals(HumanBeings): # Multi-Level Inheritance
def Powerful(self):
def powerful(self):
print("Powerful")
4 changes: 2 additions & 2 deletions basics/08_oop/10_inheritance_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Pets(Animals):

class Dog(Pets):
# We don't use @staticmethod As we use Self
def Bark(self):
def bark(self):
self.bark = True
print(self.bark)


simbu = Dog()
simbu.Bark()
simbu.bark()
12 changes: 6 additions & 6 deletions basics/08_oop/12_inheritance_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self):
print(f"LivingThings Constructor Called ! ")

@classmethod #--->The @classmethod decorator is used to work with class variables (class values) using the class (cls) instead of instance variables (self).”
def CanHearSound(self):
def can_hear_sound(self):
print(f"We Are Hear Sound {self.isLive}")

class HumanBeings(LivingThings):
Expand All @@ -15,7 +15,7 @@ def __init__(self):
super().__init__()
print("HumanBeings Constructor Called !")

def Intelligent():
def intelligent():
print("Most Intelligent ? ")

class Animals(HumanBeings):
Expand All @@ -24,9 +24,9 @@ def __init__(self):
super().__init__()
print("Animals Constructor Called !")

def Powerful():
def powerful():
print("Powerful")

Ram = LivingThings()
Ram.isLive = 12
Ram.CanHearSound()
ram = LivingThings()
ram.isLive = 12
ram.can_hear_sound()
Loading