From abbf6001730305caa0bc3d0f0757ac7af0d103dd Mon Sep 17 00:00:00 2001 From: Abhikr0 Date: Tue, 25 Jun 2024 14:25:30 +0530 Subject: [PATCH 1/2] new --- 03_loops/05_solution.py | 8 +-- 05_functions/01_solution.py | 6 +- 05_functions/02_solution.py | 7 +-- 05_functions/03_solution.py | 8 +-- 05_functions/04_solution.py | 15 ++--- 05_functions/05_soulution.py | 8 +-- 05_functions/10_solution.py | 3 +- 07_oop/01_solution.py | 23 ++------ 08_decorators/01_solution.py | 11 ++-- 08_decorators/02_solution.py | 13 +---- 09_error_handling/error_handle.py | 9 ++- 09_error_handling/youtube_manager.py | 82 ++++++++++------------------ 12 files changed, 72 insertions(+), 121 deletions(-) diff --git a/03_loops/05_solution.py b/03_loops/05_solution.py index 091ca48..49d12e8 100644 --- a/03_loops/05_solution.py +++ b/03_loops/05_solution.py @@ -1,7 +1,7 @@ -input_str = "teeteracdacd" +input_str = "teeter" for char in input_str: - print(char) + if input_str.count(char) == 1: - print("Char is: ", char) - break \ No newline at end of file + print(char) + break diff --git a/05_functions/01_solution.py b/05_functions/01_solution.py index 83971b8..153fb89 100644 --- a/05_functions/01_solution.py +++ b/05_functions/01_solution.py @@ -1,6 +1,4 @@ def square(number): - return number ** 2 + return number**2 - -result = square(4) -print(16) +square(4) \ No newline at end of file diff --git a/05_functions/02_solution.py b/05_functions/02_solution.py index d3bec3b..a5e9435 100644 --- a/05_functions/02_solution.py +++ b/05_functions/02_solution.py @@ -1,5 +1,4 @@ -def add(numOne, numTwo): - return numOne + numTwo +def two_Num(num1, num2): + return num1 + num2 - -print(add(5, 5)) \ No newline at end of file +print(two_Num(23,34)) \ No newline at end of file diff --git a/05_functions/03_solution.py b/05_functions/03_solution.py index f6fbff2..a95d397 100644 --- a/05_functions/03_solution.py +++ b/05_functions/03_solution.py @@ -1,7 +1,5 @@ -def multiply(p1, p2): - return p1 * p2 +def multiply(input1, input2): + return input1*input2 -print(multiply(8, 5)) -print(multiply('a', 5)) -print(multiply(5, 'a')) \ No newline at end of file +print(multiply(3, 'a')) \ No newline at end of file diff --git a/05_functions/04_solution.py b/05_functions/04_solution.py index 7641a2c..f8ca459 100644 --- a/05_functions/04_solution.py +++ b/05_functions/04_solution.py @@ -1,10 +1,11 @@ import math -def circle_stats(radius): - area = math.pi * radius ** 2 - circumference = 2 * math.pi * radius - return area, circumference +def cicle(radius): -a, c = circle_stats(3) - -print("Area: ", a, "Circumference: ", c) \ No newline at end of file + area = math.pi * radius**2 + circumference =2* math.pi * radius + rad = round(area,2) + circumference=round(circumference,2) + return rad,circumference + +print(cicle(5)) \ No newline at end of file diff --git a/05_functions/05_soulution.py b/05_functions/05_soulution.py index f38db28..d45228a 100644 --- a/05_functions/05_soulution.py +++ b/05_functions/05_soulution.py @@ -1,6 +1,4 @@ -def greet(name = "User"): - return "Hello, " + name + " !" +def greet(name ="User"): + return "hello "+ name +"!" - -print(greet("chai")) -print(greet()) \ No newline at end of file +print(greet("chai")) \ No newline at end of file diff --git a/05_functions/10_solution.py b/05_functions/10_solution.py index 3200d14..05c26b2 100644 --- a/05_functions/10_solution.py +++ b/05_functions/10_solution.py @@ -2,4 +2,5 @@ def factorial(n): if n == 0: return 1 else: - return n * factorial(n - 1) \ No newline at end of file + return n*factorial(n-1) + \ No newline at end of file diff --git a/07_oop/01_solution.py b/07_oop/01_solution.py index c5a154a..a12cdc6 100644 --- a/07_oop/01_solution.py +++ b/07_oop/01_solution.py @@ -13,25 +13,14 @@ def full_name(self): return f"{self.__brand} {self.__model}" def fuel_type(self): - return "Petrol or Diesel" + return "Petrol or diesel" - @staticmethod - def general_description(): - return "Cars are means of transport" - - @property - def model(self): - return self.__model - - - -class ElectricCar(Car): - def __init__(self, brand, model, battery_size): - super().__init__(brand, model) +class ElectricCar: + def __init__(self,brand,model,battery_size): + super().__init__(brand,model) self.battery_size = battery_size - - def fuel_type(): - return "Electric charge" + def fuel_type(self): + retun = "Electric Charges" # my_tesla = ElectricCar("Tesla", "Model S", "85kWh") diff --git a/08_decorators/01_solution.py b/08_decorators/01_solution.py index 9c3c141..d5955c9 100644 --- a/08_decorators/01_solution.py +++ b/08_decorators/01_solution.py @@ -3,15 +3,12 @@ def timer(func): def wrapper(*args, **kwargs): start = time.time() - result = func(*args, **kwargs) + result = func(*args,**kwargs) end = time.time() - print(f"{func.__name__} ran in {end-start} time") - return result + print(f"{func.__name__} ran in {end-start} time ") + return result return wrapper - @timer def example_function(n): - time.sleep(n) - -example_function(2) \ No newline at end of file + time.sleep(n) \ No newline at end of file diff --git a/08_decorators/02_solution.py b/08_decorators/02_solution.py index 04e0b2b..ada0ed9 100644 --- a/08_decorators/02_solution.py +++ b/08_decorators/02_solution.py @@ -1,21 +1,14 @@ - def debug(func): def wrapper(*args, **kwargs): args_value = ', '.join(str(arg) for arg in args) - kwargs_value = ', '.join(f"{k}={v}" for k, v in kwargs. - items()) + kwargs_value = ', '.join(f"{k}={v}" for k, v in kwargs.items()) print(f"calling: {func.__name__} with args {args_value} and kwargs {kwargs_value}") return func(*args, **kwargs) - return wrapper -@debug -def hello(): - print("hello") @debug -def greet(name, greeting="Hello"): +def greet(name, greeting="hello"): print(f"{greeting}, {name}") -hello() -greet("chai", greeting="hanji ") \ No newline at end of file +greet("chai",greeting="hello" ) \ No newline at end of file diff --git a/09_error_handling/error_handle.py b/09_error_handling/error_handle.py index ded2393..b0bd9c0 100644 --- a/09_error_handling/error_handle.py +++ b/09_error_handling/error_handle.py @@ -1,9 +1,8 @@ -file = open('youtube.txt', 'w') +file = open ("youtube.txt", 'w') try: - file.write('chai aur code') + file.write("Chai aur Code") finally: file.close() - -with open('youtube.txt', 'w') as file: - file.write('chai aur python') \ No newline at end of file +with open("youtube.txt", 'w') as file: + file.write("chai aur Python") \ No newline at end of file diff --git a/09_error_handling/youtube_manager.py b/09_error_handling/youtube_manager.py index 506cc4a..e52ddfe 100644 --- a/09_error_handling/youtube_manager.py +++ b/09_error_handling/youtube_manager.py @@ -1,83 +1,61 @@ - import json + + def load_data(): try: with open('youtube.txt', 'r') as file: - test = json.load(file) - # print(type(test)) - return test + return json.load(file) except FileNotFoundError: return [] -def save_data_helper(videos): +def save_data(videos): with open('youtube.txt', 'w') as file: json.dump(videos, file) def list_all_videos(videos): - print("\n") - print("*" * 70) - for index, video in enumerate(videos, start=1): - print(f"{index}. {video['name']}, Duration: {video['time']} ") - print("\n") - print("*" * 70) + for index, video in enumerate(videos,start=1): + print(f"{index}.") -def add_video(videos): +def add_a_video(videos): name = input("Enter video name: ") - time = input("Enter video time: ") - videos.append({'name': name, 'time': time}) - save_data_helper(videos) - -def update_video(videos): - list_all_videos(videos) - index = int(input("Enter the video number to update")) - if 1 <= index <= len(videos): - name = input("Enter the new video name") - time = input("Enter the new video time") - videos[index-1] = {'name':name, 'time': time} - save_data_helper(videos) - else: - print("Invalid index selected") + time = input("Enter video time:") + videos.append('name:'name',) +def update_videos(videos): + pass def delete_video(videos): - list_all_videos(videos) - index = int(input("Enter the video number to be deleted")) - - if 1<= index <= len(videos): - del videos[index-1] - save_data_helper(videos) - else: - print("Invalid video index selected") + pass + + def main(): - videos = load_data() - while True: - print("\n Youtube Manager | choose an option ") - print("1. List all youtube videos ") - print("2. Add a youtube video ") - print("3. Update a youtube video details ") - print("4. Delete a youtube video ") - print("5. Exit the app ") - choice = input("Enter your choice: ") - # print(videos) + videos =load_data() + while True : + print("\n Youtube Manager | Choose an option") + print("1. List all videos") + print("2. Add a youtube video") + print("3. update a Youtube Video") + print("4. Delete a youtube video") + print("5. Exit the program") + + choice = input("Choose") match choice: case '1': list_all_videos(videos) case '2': - add_video(videos) + add_a_video(videos) case '3': - update_video(videos) + update_videos(videos) case '4': delete_video(videos) case '5': - break + exit case _: - print("Invalid Choice") - -if __name__ == "__main__": - main() - + print("Invalid option") +if __name__== "__main__": + main() \ No newline at end of file From 4db0e3e7b985b73622a616910db8cdc29f3a9e73 Mon Sep 17 00:00:00 2001 From: Abhikr0 Date: Tue, 25 Jun 2024 14:35:49 +0530 Subject: [PATCH 2/2] k --- .gitignore | 20 -------------------- 09_error_handling/youtube_manager.py | 3 ++- 2 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 31ce655..0000000 --- a/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -Ignore virtual env in any main or sub directory - -**/venv/ -**/.venv/ -# Operating system files -.DS_Store -Thumbs.db - -# IDE and editor files -.vscode/ -.idea/ - -# Build artifacts -/build/ -/dist/ - - - -# Logs and databases -*.log diff --git a/09_error_handling/youtube_manager.py b/09_error_handling/youtube_manager.py index e52ddfe..d9e3f89 100644 --- a/09_error_handling/youtube_manager.py +++ b/09_error_handling/youtube_manager.py @@ -20,7 +20,8 @@ def list_all_videos(videos): def add_a_video(videos): name = input("Enter video name: ") time = input("Enter video time:") - videos.append('name:'name',) + videos.append('name:'name', + ) def update_videos(videos): pass