制作一个拓展课自动点名系统Python语言编程怎么写
以下是一个简单的Python代码示例,用于制作一个拓展课自动点名系统:
import random
students = ["Alice", "Bob", "Charlie", "David", "Emily", "Frank", "Grace", "Henry", "Isabella", "John"]
present = []
def roll_call():
global present
present = []
for i in range(3):
student = random.choice(students)
present.append(student)
print("{}. {}".format(i+1, student))
print("Please mark attendance for the above students.")
def main():
while True:
command = input("Enter a command (roll call, present, quit): ")
if command == "roll call":
roll_call()
elif command == "present":
print("Present students: {}".format(", ".join(present)))
elif command == "quit":
break
else:
print("Invalid command. Please try again.")
if __name__ == "__main__":
main()
这个程序有三个主要功能:点名、显示出席学生名单和退出程序。点名功能将在学生列表中随机选择三个学生,并将他们的名字打印出来。显示出席学生名单功能将打印出最近一次点名时出席的学生名单。退出程序功能将结束程序运行。
为了使用这个程序,你需要将学生的名字列表替换为你班级的学生名字。你可以将这个程序保存在一个名为“extension_class.py”的文件中,并在终端中运行它,如下所示:
$ python extension_class.py
Enter a command (roll call, present, quit): roll call
1. Emily
2. Grace
3. Isabella
Please mark attendance for the above students.
Enter a command (roll call, present, quit): present
Present students: Emily, Grace, Isabella
Enter a command (roll call, present, quit): quit
原文地址: https://www.cveoy.top/t/topic/bR1P 著作权归作者所有。请勿转载和采集!