Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed python tasks #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions MachanHoid/1a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import random
import math

n = 100

y = [random.randint(0,1) for _ in range(n)]
y_hat = [random.random() for _ in range(n)]

loss = 0
for i in range(n):
loss += y[i]*math.log(y_hat[i], 2) + (1-y[i])*math.log(1-y_hat[i],2)

print(f'Loss = {loss}')
24 changes: 24 additions & 0 deletions MachanHoid/1b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solve:
def __init__(self, numbers, target):
self.numbers = numbers
self.target = target
self.result = {}

def findpairs(self):
k = 1
for i in range(len(self.numbers)):
for j in range(len(self.numbers)):
if self.numbers[i] + self.numbers[j] == self.target:
self.result[k] = [i,j]
k += 1
#example
prob = Solve([10,20,10,40,50,60,70], 50)
prob.findpairs()
print(prob.result)

#user input
numbers = list(map(float, input("enter numbers: ").split()))
target = float(input("enter target: "))
prob2 = Solve(numbers, target)
prob2.findpairs()
print(prob2.result)