【python】”灭霸“程序

之前听说有人写了个灭霸程序可以随机删除电脑上一半的问价
这里我们用python重写下这个程序
PS:为了尽量降低伤害,我们这边只写删除当前目录下的文件

1.确认执行

为了防止用户误点开启程序,这里我们定义一个要求用户确认执行的模块,

def  user_option():
    option = input(''' 
           FBI警告
你真的确定执行这个"灭霸"程序吗?
自愿承担任何后果,任何发生的问题与本程序作者无关!
请输入你的选项?yes or no?
:''')
    if option.strip().lower() == "yes":
    #将用户的输入转化为全部小写,然后去除用户输入的左右空格,
    #检测用户输入的是否是yes,如果是yes,则返回“yes”
    #否则返回No
        return "yes"
    else:
        return "no"

2.删除文件

import os
import random
def get_del_files():
	#使用os.listdir()获取当前目录下的文件列表,
	#然后在其中移除 本程序
    file_lists = os.listdir()
    file_lists.remove("灭霸.py")
    #获取文件列表
    #随机删除一般的文件
    file_num = len(file_lists) // 2
    for  user in  range(file_num):
        file = random.choice(file_lists)
        os.popen("del {}".format(file))
        file_lists.remove(file)
        print ("灭霸正在摧毁{}。。。".format(file))

3.主程序

def main():
    ####################检测用户输入
    timeout = 0.1
    while True:
        if user_option() == "yes":
            print ("\n灭霸正在安装力量之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装时间之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装空间之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装灵魂之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装现实之石。。\n")
            time.sleep(timeout)
            break
        else:
            print ("你不同意执行,程序将无法执行!!!")
            continue
    ####################灭霸进行时。。。
    get_del_files()
    print ("\n灭霸成功的摧毁了一半的世界,复仇者联盟感觉很失落!!!")
    print ("你是个坏人,居然帮助灭霸!w(゚Д゚)w")
    print ("哼,不理你了!!! ̄へ ̄")
    input("按任意键以退出程序。。")

完整代码

# -*- coding:utf-8 -*-
import os
import random
import time

def  user_option():
    option = input(''' 
           FBI警告
你真的确定执行这个"灭霸"程序吗?
自愿承担任何后果,任何发生的问题与本程序作者无关!
请输入你的选项?yes or no?
:''')
    if option.strip().lower() == "yes":
        return "yes"
    else:
        return "no"


def get_del_files():
    file_lists = os.listdir()
    file_lists.remove("灭霸.py")
    #获取文件列表
    file_num = len(file_lists) // 2
    for  user in  range(file_num):
        file = random.choice(file_lists)
        os.popen("del {}".format(file))
        file_lists.remove(file)
        print ("灭霸正在摧毁{}。。。".format(file))
    

def main():
    ####################检测用户输入
    timeout = 0.1
    while True:
        if user_option() == "yes":
            print ("\n灭霸正在安装力量之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装时间之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装空间之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装灵魂之石。。",end="")
            time.sleep(timeout)
            print ("\n灭霸正在安装现实之石。。\n")
            time.sleep(timeout)
            break
        else:
            print ("你不同意执行,程序将无法执行!!!")
            continue
    ####################灭霸进行时。。。
    get_del_files()
    print ("\n灭霸成功的摧毁了一半的世界,复仇者联盟感觉很失落!!!")
    print ("你是个坏人,居然帮助灭霸!w(゚Д゚)w")
    print ("哼,不理你了!!! ̄へ ̄")
    input("按任意键以退出程序。。")
main()
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值