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
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?
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")