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

perfect sq #53

Open
wants to merge 3 commits into
base: master
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
28 changes: 28 additions & 0 deletions cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 25 16:36:54 2021

@author: deyasini
"""

def cipher(map_from, map_to, code):
""" map_from, map_to: strings where each contain
N unique lowercase letters.
code: string (assume it only contains letters also in map_from)
Returns a tuple of (key_code, decoded).
key_code is a dictionary with N keys mapping str to str where
each key is a letter in map_from at index i and the corresponding
value is the letter in map_to at index i.
decoded is a string that contains the decoded version
of code using the key_code mapping. """
key_code={}
i=0
d=[]
for char in map_from:
key_code[char]=map_to[i]
i+=1

for char in code:
d.append(key_code[char])
decoded=''.join(d)
return (key_code, decoded)
15 changes: 15 additions & 0 deletions perfect_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 26 18:39:44 2021

@author: deyas
"""

def is_square(n):
ans=0
while ans**2<n:
ans+=1
if ans**2==n:
print ("perfect sq")
else:
print ("not perfect sq")