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
15 changes: 15 additions & 0 deletions homeworks/10_functions/find_factors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def factors(num):
result = []
if num < 1:
return result
else:
for i in range(1, num+1):
# print (i)
# print(num%i)
if (num%i == 0):
# print(num/i)
result.append(i)
return result

num = int(input("enter the num:"))
print (factors(num))
22 changes: 22 additions & 0 deletions homeworks/10_functions/star_rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
To create a Rectangle like the below:

*******
* *
* *
* *
* *
*******

"""

def star_rectangle(width, length):
for i in range(0, length):
if i == 0 or i == length -1:
print("*" * width)
else:
print("*", ' ' * (width - 4), "*")



star_rectangle(7, 6)
9 changes: 9 additions & 0 deletions homeworks/10_functions/sum_of_digits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def sum_digit(num):
result = 0
for i in num:
if i.isdigit():
result += int(i)
return result

num = input("enter a number:")
print(sum_digit(num))
13 changes: 13 additions & 0 deletions homeworks/11_exceptions/safe_division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def safe_divide(num, den):
try:
print(f"The result is {num / den}")

except ZeroDivisionError:
print("ERROR: Cannot be divided by zero")
finally:
print("Division is done")


num = int(input("Enter the numerator:"))
den = int(input("Enter the denominator:"))
safe_divide(num, den)
9 changes: 9 additions & 0 deletions homeworks/11_exceptions/voting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def check_voter_age(age):
if age < 18:
raise ValueError("Not eligible to vote")
print("Eligible to vote")
try:
age = int(input("Enter the age:"))
check_voter_age(age)
except ValueError as e:
print ("Error:", e)
35 changes: 35 additions & 0 deletions homeworks/12_modules/cli_task_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import argparse

def list_TASKS(TASKS):
if len(TASKS) != 0:
for item in TASKS:
print (item)
else:
print("No Tasks Available")

def update_TASKS (operation):
if operation == "add":
task = input("Enter the task to add:")
TASKS.append(task)
print("Task Updated")
elif operation == "delete":
pass

TASKS = []
parser = argparse.ArgumentParser()
# parser.add_argument("add", help = "Add new task")
# parser.add_argument("delete", help = "Delete existing task")
parser.add_argument("--operation", help = "Add or Remove a task from manager", choices=["add", "delete"])
parser.add_argument("--list", help = "List all tasks", action="store_true")
args = parser.parse_args()

if args.operation == "add":
update_TASKS("add")
elif args.operation == "delete":
update_TASKS("delete")

if args.list:
list_TASKS(TASKS)



16 changes: 16 additions & 0 deletions homeworks/13_file_handling/file_content_reverser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def reverser():
try:
lines = []
with open ("test.txt", "r") as f:
lines = f.readlines()
# print (lines)
f.close()
with open ("test.txt","w") as f:
for line in lines[::-1]:
f.writelines(line.rstrip("\n") + "\n")
# f.write()
print("File reversed")
except FileNotFoundError:
print("Error: File Not Found")

reverser()
12 changes: 12 additions & 0 deletions homeworks/13_file_handling/safe_file_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def safe_file_reader():
try:
with open("test1.txt", "r") as f:
print("Test file found successfully...\n")
lines = f.readlines()
for line in lines:
print(line)
except FileNotFoundError:
print("Error: Test file is not available in current directory")
return None

safe_file_reader()
2 changes: 2 additions & 0 deletions homeworks/13_file_handling/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hi Logi
How are you?
40 changes: 40 additions & 0 deletions homeworks/15_oops/multi-level_inheritance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Animal:
def __init__(self, name):
self.name = name
def eat(self):
return f"{self.name} is eating"

class Mammal(Animal):
def __init__(self,name,has_fur):
super().__init__(name)
self.has_fur = has_fur
def walk(self):
return f"{self.name} is walking"

class Dog(Mammal):
def __init__(self,name,has_fur,breed):
super().__init__(name,has_fur)
self.breed = breed
def bark(self):
return f"{self.name} can Bark"
def fur_info(self):
if self.has_fur == True:
return f"{self.name} is having fur"
else:
return f"{self.name} does not have fur"

class Cat(Mammal):
def __init__(self, name, has_fur, breed):
Mammal.__init__(self,name,has_fur)
self.breed = breed
def meow(self):
return f"{self.name} can meow"


if __name__ == '__main__':
a = Dog(name="Leo", has_fur=True, breed="Labrador")
print(a.walk(), '\n', a.bark())
print (a.fur_info())

b = Cat(name="Min", has_fur=False, breed="Persian")
print(b.walk(), '\n', b.meow())
24 changes: 24 additions & 0 deletions homeworks/15_oops/multiple_inheritance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Phone:
def __init__(self, brand, number):
self.brand = brand
self.number = number

def call(self):
return f"Calling from {self.number} with {self.brand}"

class Camera:
def __init__(self, mps):
self.mps = mps

def take_photo(self):
return f"Taking photo with {self.mps} megapixels camera"

class Smartphone(Phone, Camera):
def __init__(self,brand,number,mps):
Phone.__init__(self,brand,number)
Camera.__init__(self,mps)

sp = Smartphone(brand= 'Iphone', number=123456789, mps=45)

print(sp.call())
print(sp.take_photo())
21 changes: 21 additions & 0 deletions homeworks/15_oops/pet_simulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Pet:
def __init__(self, name, hunger, happiness, health):
self.name = name
self.hunger = hunger
self.happiness = happiness
self.health = health

def get_status(self):
return f"Pet name is {self.name}, it is {self.hunger} & {self.happiness}. It's health is {self.health}"
def feed(self):
return f"{self.name} is eating"

def play(self):
self.happiness = "Happy"
return f"{self.name} is {self.happiness}"


pet = Pet("Leo", "Hungry", "Sad", "Average")
print(pet.get_status())
print(pet.feed())
print(pet.play())
22 changes: 22 additions & 0 deletions homeworks/15_oops/single_inheritance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary

def get_employee_info(self):
return (f"Employee Name: {self.name}, Employee Salary: {self.salary}")

class Manager(Employee):
def __init__(self, name, salary, dept):
super().__init__(name,salary)
self.dept = dept

def get_manager_info(self):
return (f"Manager Info:{self.name}, Manager Salary: {self.salary}, Manager Department: {self.dept}")

if __name__ == '__main__':
emp = Employee("Ajay", 20000)
mgr = Manager("Logi", 200000, "SW & ADAS")
print(emp.get_employee_info())
print(mgr.get_employee_info())
print(mgr.get_manager_info())
32 changes: 32 additions & 0 deletions homeworks/15_oops/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# class Vehicle:
# def __init__(self, wheels, color):
# self.wheels = wheels
# self.color = color
# class Car(Vehicle):
# def __init__(self, wheels, color, gears):
# super().__init__(wheels, color)
# self.gears = gears
# def gear_info(self):
# return (f"{self.color} Car has {self.gears} gears")
#
# honda = Vehicle(wheels=2, color="White")
# honda_car = Car(wheels=4, color="Black", gears= 6)
# print(honda.color, honda.wheels)
# print(honda_car.color, honda_car.wheels)
# print (honda_car.gear_info())


class Vehicle:
def __init__(self):
self.wheels = 2
self.color = "Black"
class Car(Vehicle):
def __init__(self):
super().__init__()
self.wheels = 4

bike = Vehicle()
car = Car()

print (bike.color , bike.wheels)
print (car.color, car.wheels)
3 changes: 3 additions & 0 deletions homeworks/ch1-hw1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user_name= input("Enter your name:")
fav_color= input("Enter favourite color:")
print (f"Hi,{user_name}. {fav_color} is your favourite color")
4 changes: 4 additions & 0 deletions homeworks/ch1-hw2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
user_addr= input("Enter user address:")
item_name= input("Enter Item name:")
item_cost= input("Enter item cost:")
print(f"Address:{user_addr} \n Item Purchased:{item_name} \n Item Cost:${item_cost}")
2 changes: 2 additions & 0 deletions homeworks/ch1-hw3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prompt = input("Hi, Tell me what you have learnt today?\n")
print(f"Amazing to hear!! You have learnt {prompt}")
3 changes: 3 additions & 0 deletions homeworks/ch2-hw1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
inch = float(input("Enter the inches:"))
cm = inch * 2.54
print (f"{inch} inches is equal to {cm}cm")
3 changes: 3 additions & 0 deletions homeworks/ch2-hw2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fah = float(input("Enter the Fahrenheit:"))
Cel = float ((fah - 32) * (5/9))
print (f"{fah} Fahrenheit is {round(Cel,2)} Celsius")
5 changes: 5 additions & 0 deletions homeworks/ch2-hw3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
principal = int(input("Enter the principal amount:"))
rate = int(input("enter the rate of interest:"))
time = int(input("enter the time period:"))
SI = round((float((principal * rate * time)/100)),1)
print ("The total simple interest is",SI)
5 changes: 5 additions & 0 deletions homeworks/ch3-hw1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a= int(input("enter the no:"))
if ( a >= -3 and a <= 7):
print(f"the number {a} belongs to the interval")
else:
print(f"the number {a} doesn't belong to the interval")
6 changes: 6 additions & 0 deletions homeworks/ch3-hw2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = int(input("enter the no:"))
if ((a>= -30 and a <= -25) or (a >= 7 and a <= 25)):
print (f"the number {a} belong to the interval")
else:
print(f"the number {a} does not belong to the interval")

9 changes: 9 additions & 0 deletions homeworks/ch3-hw3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
weight = int(input("Enter the bodyweight:"))
if (weight > 64 and weight <=69):
print("Middleweight")
elif (weight> 60 and weight <=64):
print ("First Middleweight")
elif (weight<= 60):
print ("LightWeight")
else:
print("Not a valid weight category")
7 changes: 7 additions & 0 deletions homeworks/ch3-hw4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = int(input("Enter first value for triangle:"))
b = int(input("Enter second value for triangle:"))
c = int(input("Enter third value for triangle:"))
if ((a+b)<c or (a+c)<b or (b+c)<a):
print("NO")
else:
print ("YES")
10 changes: 10 additions & 0 deletions homeworks/ch3-hw5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
city1 = input("Enter first city name:")
city2 = input("Enter second city name:")
city3 = input("Enter third city name:")

if (len(city1) > len(city2) and len(city1)>len(city3)):
print (city1)
elif (len(city2)>len(city1) and len(city2)>len(city3)):
print(city2)
elif (len(city3)>len(city1) and len(city3)>len(city2)):
print(city3)
8 changes: 8 additions & 0 deletions homeworks/reverse-sentence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ip = []
# print ("Enter 3 lines:\n")
# for i in range(4):
# line= input()
# line = ip.append()
# print(line[0,])

print (10//3)
6 changes: 6 additions & 0 deletions homeworks/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a= int(input("enter the no:"))
print(f"raw_input of{a}")
if ( a >= -3 and a <= 7):
print(f"the number {a} belongs to the interval")
else:
print(f"the number {a} doesn't belong to the interval")
6 changes: 6 additions & 0 deletions homeworks/test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = int(input("enter the no:"))
if ((a>= -30 and a <= -25) or (a >= 7 and a <= 25)):
print (f"the number {a} belong to the interval")
else:
print(f"the number {a} does not belong to the interval")