PY_NEWBIE
PY_NEWBIE

Reputation: 77

python code just won't work. the decryption doesn't return back the decrypted phrase

I tried putting print hello's everywhere and tried to find what wasn't working, and the if filename == x part wouldn't work. there certainly is the text.txt file. the program won't respond. It's like the code doesn't exist please help

import os
def translate(y):
    y = y.replace("quebrqerubfq92983rgh", "A")

x = "text.txt"
a = os.path.realpath(__file__)
a = a.split(":")
a = a[0]
for foldername, subfolders, filenames in os.walk(a + ":"):
    for subfolder in subfolders:
        for filename in filenames:
            if filename == x:
                s = open(x, "r")
                y = s.read()
                y = str(y)
                result = translate(y)
                s = s.close()

Upvotes: 0

Views: 72

Answers (1)

lbal
lbal

Reputation: 291

You are not printing, returning, nor writing anything, that's your problem. Your translate function needs a return. And what do you want to do with y after you translated it?

Edit: try this out.

import os
def translate(y):
    y = y.replace("quebrqerubfq92983rgh", "A")
    return y

x = "text.txt"
a = os.path.realpath(__file__)
a = a.split(":")
a = a[0]
for foldername, subfolders, filenames in os.walk(a + ":"):
    for subfolder in subfolders:
        for filename in filenames:
            if filename == x:
                s = open(x, "r")
                y = s.read()
                y = str(y)
                result = translate(y)
                s = s.close()

print(result)

Upvotes: 1

Related Questions