Create an app that guesses students with python

Introduction

At the high school I go to, a mathematics teacher used Excel to make a "guy who guesses students" and used it to guess students, so I made an improved version of it by making python.

How the Excel version works

  1. Randomly select students and display them on the screen
  2. If the student has hit in the past, the cell next to the name will turn red
  3. Record the students who hit (clear when it makes a round)

(I have not obtained permission from the teacher, so I will refrain from details)

Improvement

  1. Students are selected from all the students each time, and one has to judge whether or not they have been hit once. → Students who hit once will not be displayed until they make a round
  2. The teacher manually records the hit students by copying. → Automate recording

Functions to implement

  1. Display name
  2. Skip absentees
  3. Reset the list
  4. View list
  5. View history
  6. Clear history
  7. Update the list
  8. Clear console

program

The guy who guesses the student.py


import random
import pickle
import os
import sys
import datetime

name = None

if os.name == 'nt':
    os.system('cls')
elif os.name == 'posix':
    os.system('clear')

print("See help for how to use")

while True:

    a = input('>')

    if a == "help":
        print("Enter----Display name\n"
              "pass-----Skip absentees\n"
              "reset----List reset\n"
              "ls-------View list\n"
              "history--View history\n"
              "Clear history with clear at the end\n"
              "setup----Update the list\n"
              "clear----Clear console\n"
              "exit-----End")

    elif a == "ls":

        if name != None and name in list:
            list.remove(name)
            f = open('list.txt', 'wb')
            pickle.dump(list, f)
        if list == []:
            f = open("./list_raw.txt", "rb")
            list_raw = pickle.load(f)

            list = list_raw

            f = open('list.txt', 'wb')
            pickle.dump(list, f)

        f = open("./list.txt", "rb")
        list = pickle.load(f)
        for i in list:
            print(i)

    elif a == "reset":
        f = open("./list_raw.txt", "rb")
        list_raw = pickle.load(f)

        list = list_raw

        f = open('list.txt', 'wb')
        pickle.dump(list, f)
        name = None

    elif a == "clear":
        if os.name == 'nt':
            os.system('cls')
        elif os.name == 'posix':
            os.system('clear')

    elif a == "setup":

        if os.name == 'nt':
            os.system('cls')
        elif os.name == 'posix':
            os.system('clear')

        print("1)Text file with any file name(*.txt)Create a.\n"
              "2)In it\n1.name\n2.name\Hmm·\Hmm·\Hmm·\Enter n.\n"
              "3)setup>Enter the file name after.\n"
              "4)Type exit to exit.")

        while True:

            a = input("setup>")

            if a == "exit":
                if os.name == 'nt':
                    os.system('cls')
                elif os.name == 'posix':
                    os.system('clear')
                break

            else:

                if os.path.isfile(a):

                    f = open(a, "r")
                    list = []

                    for x in f:
                        list.append(x.rstrip("\n"))
                    f.close()

                    f = open('list.txt', 'wb')
                    pickle.dump(list, f)

                    f = open('list_raw.txt', 'wb')
                    pickle.dump(list, f)

                    history = []
                    f = open('history.txt', 'wb')
                    pickle.dump(history, f)

                else:
                    print("Please enter the exact file name.")

    elif a == "history":

        f = open("./history.txt", "rb")
        history = pickle.load(f)

        for i in history:
            print(i)

        f = open('history.txt', 'wb')
        pickle.dump(history, f)

    elif "history" in a and "clear" in a:

        f = open("./history.txt", "rb")
        history = pickle.load(f)

        history = []

        f = open('history.txt', 'wb')
        pickle.dump(history, f)

    elif a == "exit":
        sys.exit()

    elif a == "pass":
        pass

    elif a == "":
        if name == None:
            pass

        else:
            if name in list:
                list.remove(name)

            if list != None:
                f = open('list.txt', 'wb')
                pickle.dump(list, f)

            if list == []:
                f = open("./list_raw.txt", "rb")
                list_raw = pickle.load(f)

                list = list_raw
                f = open('list.txt', 'wb')
                pickle.dump(list, f)

    else:
        print(a + ":Command not found")

    if a == "" or a == "pass":

        f = open("./list.txt", "rb")
        list = pickle.load(f)

        # print(list)

        name = random.choice(list)

        print(name)

        f = open("./history.txt", "rb")
        history = pickle.load(f)

        now = datetime.datetime.now()

        history.append(now.strftime('%m month%d day') + ":" + name)

        f = open('history.txt', 'wb')
        pickle.dump(history, f)

Ready to use

  1. Create the following files in the same directory as the program  1.list.txt  2.list_raw.txt  3.history.txt  4.namelist.txt

2.namelist.txt Edit as below

namelist.txt


1.Yamada Taro
2.Hanako Yamada
  1. Run the program and run setup

Operation scenery

Screenshot from 2020-02-16 11-07-36.png Screenshot from 2020-02-16 11-07-39.png Screenshot from 2020-02-16 11-07-48.png Screenshot from 2020-02-16 11-07-53.png Screenshot from 2020-02-16 11-07-59.png Screenshot from 2020-02-16 11-08-30.png Screenshot from 2020-02-16 11-08-32.png Screenshot from 2020-02-16 11-08-34.png Screenshot from 2020-02-16 11-08-47.png

Summary

It's a pity that it's not easy for everyone to use because it's CUI. That doesn't mean I'm going to make it a GUI. (I can't make it even if I want to make it because I don't have the ability to design ...)

I made a GUI version for some reason Create an app that guesses students with python-GUI version

Recommended Posts

Create an app that guesses students with python
Create an app that guesses students with python-GUI version
Create an English word app with python
Create an Excel file with Python3
Let's create an app that authenticates with OIDC with Azure AD
Quickly create an excel file with Python #python
[Python] Quickly create an API with Flask
Create test data like that with Python (Part 1)
Create an image composition app with Flask + Pillow
Create a page that loads infinitely with python
Create an image with characters in python (Japanese)
Create an API server quickly with Python + Falcon
[kotlin] Create an app that recognizes photos taken with a camera on android
Create an app that works well with people's reports using the COTOHA API
Create an animated GIF local server with Python + Flask
Create an environment with virtualenv
Create an API with Django
Create 3d gif with python3
Creating an egg with python
Create a directory with python
Let's make an app that can search similar images with Python and Flask Part1
Let's make an app that can search similar images with Python and Flask Part2
Create an exe file that works in a Windows environment without Python with PyInstaller
Let's create a script that registers with Ideone.com in Python.
Create an LCD (16x2) game with Raspberry Pi and Python
How to run an app built with Python + py2app built with Anaconda
Create a Todo app with Django ① Build an environment with Docker
[Python Kivy] How to create an exe file with pyinstaller
Cut out an image with python
Create plot animation with Python + Matplotlib
Create Awaitable with Python / C API
Create folders from '01' to '12' with python
Create a virtual environment with Python!
I sent an SMS with Python
Create an age group with pandas
Draw an illustration with Python + OpenCV
[Python] Send an email with outlook
Create REST API that returns the current time with Python3 + Falcon
How to create a heatmap with an arbitrary domain in Python
[LINE Messaging API] Create a BOT that connects with someone with Python
Create an app that notifies LINE of the weather every morning
Create an application that just searches using the Google Custom Search API with Python 3.3.1 in Bottle
Create an automatic grade management app for Tenhou private room with LINE bot and Python Part 1
Create an automatic grade management app for Tenhou private room with LINE bot and Python Part 2
Create an automatic grade management app for Tenhou private room with LINE bot and Python Part ③
Create an application by classifying with Pygame
Create a Python function decorator with Class
[Python] A program that creates stairs with #
Automatically create Python API documentation with Sphinx
Creating an image splitting app with Tkinter
Create wordcloud from your tweet with python3
Build a blockchain with Python ① Create a class
Create an image processing viewer with PySimpleGUI
Create a dummy image with Python + PIL.
Uncle SES modernizes VBA app with Python
Note when creating an environment with python
Create a web app that can be easily visualized with Plotly Dash
Create a simple GUI app in Python
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a GUI app with Python's Tkinter