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

commit 1 by Aditya #18

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
14 changes: 14 additions & 0 deletions Task-1-A.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import random
import math

y1 = [] # for floats - y^
y2 = [] # for 0s and 1s - y

for i in range(100):
y1.append(random.random())
y2.append(random.randint(0, 1))
sum = 0
for i in range(100):
sum += y2[i]*math.log(y1[i], 2) + (1-y2[i])*math.log((1-y1[i]), 2)
sum = -sum/100
print(sum)
23 changes: 23 additions & 0 deletions Task-1-B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class TaskB:
def inp(self):
self.n = list(map(int, input("Enter elements separated by a space and enter to finish\n").split()))
self.target = int(input("Enter target sum value\n"))
self.l = len(self.n)
def calc(self):
self.Dict = {}
self.c = 1
for i in range(self.l):
for j in range(self.l):
if(i==j):
continue
if((self.n[i]+self.n[j]) == self.target):
self.Dict[self.c] = [i, j]
self.c = self.c + 1
def output(self):
print(self.Dict)

obj = TaskB()

obj.inp()
obj.calc()
obj.output()