forked from pravocodes/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pravocodes#1 from kumar-karan/my-new-branch
Added Python scripts for calculator, data analysis, to-do list
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |