Skip to content

Commit

Permalink
Merge pull request pravocodes#1 from kumar-karan/my-new-branch
Browse files Browse the repository at this point in the history
Added Python scripts for calculator, data analysis, to-do list
  • Loading branch information
hackelite01 authored Oct 2, 2024
2 parents 6bf8d61 + 9091533 commit e8ed3c5
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Python/calculator.py
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")
18 changes: 18 additions & 0 deletions Python/data_analysis.py
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()
29 changes: 29 additions & 0 deletions Python/matrix_multiplication.py
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 added Python/my_python_script.py
Empty file.
50 changes: 50 additions & 0 deletions Python/to_do_list.py
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()

0 comments on commit e8ed3c5

Please sign in to comment.