python嵌套if语句与用户输入不起作用

时间:2016-12-29 15:04:09

标签: python python-3.x

我不知道为什么,但是当我开始测试这个时,无论我输入哪个字母,它都会丢弃打印("此文件被删除")而没有其他选项。嵌套if语句肯定有问题。

import os, shutil, send2trash

def delete_files(folder):
    for folderName, subfolders, filenames in os.walk(folder):
        for filename in filenames:
            full_file_name = os.path.join(folderName, filename)
            size = os.path.getsize(full_file_name)
            if size > 100000000:
                print(filename, size)
                print("Do you want to delete this file?")
                confirm = input("Y or N? ")
                if confirm == "Y" or "y":
                    print("THIS FILE IS DELETED")
                    #send2trash.send2trash(filename)
                elif confirm == "N" or "n":
                    print("Let`s keep this file!")
delete_files(r"M:\Tables_Field\Processing\!-=ieksejie dokumenti=-\!Emīls")

0 个答案:

没有答案