Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
26 changes: 17 additions & 9 deletions bigrandom/answer.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
class BigRandom:
def __init__(self):
self.data = "data.txt"
# add attributes if you need more
self.data = "data.txt"

def answer(self):
noh = 0 # variable to store number of hashtag
# ommiting line number's hashtag
suc = 0 # variable to store sum of character's code in ascii,
# ommiting line number and its hashtag
self.data = open("data.txt", "r")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jangan ngubah nilai atribut

noh, suc = 0, 0
for line in self.data.readlines():
noh = noh + len([x for x in line if x == '#']) #______ count of '#'
suc = suc + sum([ord(x) for x in line]) #_____________ sum of asciis of all chars

# your algorithm

numbs = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000

return (noh,suc)
self.data.close() # close data stream

# add methods if you need more
# ord('#') * 10000 _________________ sum of asciis of first '#' in each row
# sum([ord(x) for x in nomor]) _____ sum of asciis of numbs
return (noh - 10000, suc - (ord('#') * 10000 + sum([ord(x) for x in numbs])))

# instantiation
big = BigRandom()
a, b = big.answer()
print(a, b)
15 changes: 9 additions & 6 deletions caesar/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ def __init__(self):
# add attributes if you need more

def answer(self):
key = 0 # variable to store the key
self.ciphertext = open("ciphertext.txt", "r+")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jangan ngubah nilai atribut

key = int(raw_input(":> ")) # _____________________________________________________ get key from user
msg = ''.join([chr(ord(x) - key) for x in str(self.ciphertext.readlines())]) # ____ decripting @return decripted string
print("Hasil decrypt dengan key %d adalah \n %s" % (key, msg)) # __________________ printing out
self.ciphertext.close() # _________________________________________________________ close data stream
return (msg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kok return nya jadi ini??


# your algorithm

return (key)

# add methods if you need more
# instantiation
csr = Caesar()
print(csr.answer());