diff --git a/Python/calculator.py b/Python/calculator.py new file mode 100644 index 0000000..dfddc7d --- /dev/null +++ b/Python/calculator.py @@ -0,0 +1,42 @@ +# Python program to create a simple calculator + +def add(x, y): + return x + y + +def subtract(x, y): + return x - y + +def multiply(x, y): + return x * y + +def divide(x, y): + if y == 0: + return "Division by zero is not allowed" + return x / y + +print("Select operation:") +print("1. Add") +print("2. Subtract") +print("3. Multiply") +print("4. Divide") + +while True: + choice = input("Enter choice(1/2/3/4): ") + + if choice in ('1', '2', '3', '4'): + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + if choice == '1': + print(f"The result is: {add(num1, num2)}") + + elif choice == '2': + print(f"The result is: {subtract(num1, num2)}") + + elif choice == '3': + print(f"The result is: {multiply(num1, num2)}") + + elif choice == '4': + print(f"The result is: {divide(num1, num2)}") + else: + print("Invalid input") diff --git a/Python/data_analysis.py b/Python/data_analysis.py new file mode 100644 index 0000000..95f1d0f --- /dev/null +++ b/Python/data_analysis.py @@ -0,0 +1,18 @@ +import pandas as pd +import matplotlib.pyplot as plt + + +data = pd.read_csv('data.csv') + +print("Data Preview:") +print(data.head()) + +print("\nSummary Statistics:") +print(data.describe()) + +plt.figure(figsize=(10, 5)) +plt.hist(data['age'], bins=20, color='blue', edgecolor='black') +plt.title('Age Distribution') +plt.xlabel('Age') +plt.ylabel('Frequency') +plt.show() diff --git a/Python/matrix_multiplication.py b/Python/matrix_multiplication.py new file mode 100644 index 0000000..f275518 --- /dev/null +++ b/Python/matrix_multiplication.py @@ -0,0 +1,29 @@ +def matrix_multiplication(A, B): + result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))] + + for i in range(len(A)): + for j in range(len(B[0])): + for k in range(len(B)): + result[i][j] += A[i][k] * B[k][j] + + return result + +A = [[1, 2, 3], + [4, 5, 6], + [7, 8, 9]] + +B = [[9, 8, 7], + [6, 5, 4], + [3, 2, 1]] + +result = matrix_multiplication(A, B) + +print("Matrix A:") +for row in A: + print(row) +print("\nMatrix B:") +for row in B: + print(row) +print("\nResult of A * B:") +for row in result: + print(row) diff --git a/Python/my_python_script.py b/Python/my_python_script.py new file mode 100644 index 0000000..e69de29 diff --git a/Python/to_do_list.py b/Python/to_do_list.py new file mode 100644 index 0000000..b40eda8 --- /dev/null +++ b/Python/to_do_list.py @@ -0,0 +1,50 @@ +def display_tasks(): + with open("tasks.txt", "r") as f: + tasks = f.readlines() + if not tasks: + print("No tasks in the to-do list.") + else: + print("To-Do List:") + for i, task in enumerate(tasks): + print(f"{i + 1}. {task.strip()}") + +def add_task(task): + with open("tasks.txt", "a") as f: + f.write(task + "\n") + print("Task added successfully!") + +def remove_task(task_number): + with open("tasks.txt", "r") as f: + tasks = f.readlines() + if task_number > len(tasks) or task_number < 1: + print("Invalid task number!") + else: + del tasks[task_number - 1] + with open("tasks.txt", "w") as f: + f.writelines(tasks) + print("Task removed successfully!") + +def main(): + while True: + print("\n1. View Tasks") + print("2. Add Task") + print("3. Remove Task") + print("4. Quit") + + choice = input("Enter your choice: ") + + if choice == "1": + display_tasks() + elif choice == "2": + task = input("Enter the task: ") + add_task(task) + elif choice == "3": + task_number = int(input("Enter task number to remove: ")) + remove_task(task_number) + elif choice == "4": + break + else: + print("Invalid choice!") + +if __name__ == "__main__": + main()