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.
(I have not obtained permission from the teacher, so I will refrain from details)
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)
2.namelist.txt Edit as below
namelist.txt
1.Yamada Taro
2.Hanako Yamada
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