admin 管理员组文章数量: 1184232
你想要一个自己就会做的操作系统吗?
立即教会你!
安排!
Python得有,用来编写“操作系统”用 下载地址:欢迎来到 Python
微软的Visual Code也可以
下载好之后,在任意位置新建文本文档,然后重命名,把txt变成py
右键用编程工具打开,一定要改打开方式,不然只有一个一闪而过的cmd窗口
好了,开始编程!
import time as tm
import getpass
import datetime
import calendar
import os
以上这些是引入module
没有这些会报错
print("BBC OS (R) Core Open Source System 1.2")
print("Avaliable update! Visit bbc to update")
以上这些是“开机”自动弹出的话
你们可以改,我这里拿BBC OS做例子
count = 0
stpasswd = "114514"
以上设置密码为“114514”
你们可以改
while count < 3:
user = input("Login: ")
if user == "root":
while count < 3:
passwd = getpass.getpass("Password: ")
if passwd == stpasswd:
以上是登录部分
tm.sleep(1.5)
while count < 3:
cmd = input("~ $ ")
if cmd == "ls":
print("Downloads Documents Music Pictures")
elif cmd == "version":
print("BBC OS (R) Core Open Source System 1.2 ")
elif cmd == "coverter":
print("File Covert\nCovert .lpap/.lpcu/.bbc to .umm")
input("Input file's path:\n")
print("Coverting [____________________] 0%")
tm.sleep(0.3)
print("Coverting [######______________] 30%")
tm.sleep(0.3)
print("Coverting [############________] 60%")
tm.sleep(0.3)
print("Coverting [################____] 80%")
tm.sleep(0.3)
print("Coverting [####################] 100%")
tm.sleep(0.09)
以上是进度条
print("Covert Complete.")
elif cmd == "time":
now = datetime.datetime.now()
other_StyleTime = now.strftime("%Y-%m-%d %H:%M:%S")
print(other_StyleTime)
以上是时间功能
elif cmd == "passwd":
stpasswd = input("Input new password: ")
以上是重置密码功能
elif cmd == "calendar":
yy = int(input("Year: "))
mm = int(input("Month: "))
print(calendar.month(yy, mm))
以上是日历功能
elif cmd == "help":
print("ls View the path")
print("version Show the system's version")
print("coverter A tool to covert .lpap/.lpcu/.bbc to .umm")
print("time Show the time and date")
print("calendar Show a calendar")
print("calc A simple calculator")
print("clear Clean the screen")
print("passwd Change your password")
print("exit Log out")
以上是help帮助面板
elif cmd == "calc":
try:
formula = input("Enter the formula to be calculated:\n")
print(formula + "=", eval(formula))
except Exception as e:
print("Input error.")
以上是计算器模块
elif cmd == "clear":
i = os.system("cls")
以上是清屏模块
elif cmd == "exit":
break
以上是退出模块
else:
print("Unknown command.")
以上是未知代码提示
else:
print("Error password! Please retry")
以上是密码错误提示
else:
print("Invalid user! Please retry")
以上是用户名错误提示
编写完成,收工!
转载请注明出处,谢谢
版权声明:本文标题:自己开发一个“操作系统”,小白也会!(基于Python) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1738179719a1938268.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论