猫史档案馆


【Python作品分享】SunriseOS【作品秀】

用户:MikorisMikoris查看:0 回复:0 评论:0 创建时间:2022-11-11T21:37:22


【作品展示】

center_image

 

【作品介绍】

操作系统:SunriseOS

单线程,可暂存文件,

*使用前必看*:“>”后的代码必须包含三个植,中间以空格分割。

如:information . .

获取帮助请输入"help . ."

获取相关信息请输入“information . ."

 

【作品源代码】

# Let's go!
import os
import webbrowser
from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from tkinter.messagebox import *
import tkinter
import random
import datetime
big_line = "》------------------------------------------------《"
print("")

print(big_line)
print("""
 / ____|                (_)         / __ \ / ____|
 | (___  _   _ _ __  _ __ _ ___  ___| |  | | (___  
  \___ \| | | | '_ \| '__| / __|/ _ \ |  | |\___ \ 
  ____) | |_| | | | | |  | \__ \  __/ |__| |____) |
 |_____/ \__,_|_| |_|_|  |_|___/\___|\____/|_____/                                                    
""")
print("                *Black Play出品*")
print("输入“help”获取帮助,输入“information”获取相关信息")
print(big_line)


# *变量与函数准备*


def if_get(game_1_get2):
    if game_1_get2 == 1:
        print("电脑出了剪刀")
    if game_1_get2 == 2:
        print("电脑出了石头")
    if game_1_get2 == 3:
        print("电脑出了布")


# 猜拳游戏电脑说明


# 摩斯电码的字典
def Morse_code(x):
    dic = {'A': '._', 'B': '_...', 'C': '_._.', 'D': '_..', 'E': '.', 'F': '.._.',
           'G': '__.', 'H': '....', 'I': '..', 'J': '.___', 'K': '_._', 'L': '._..',
           'M': '__', 'N': '_.', 'O': '___', 'P': '.__.', 'Q': '__._', 'R': '._.',
           'S': '...', 'T': '_', 'U': '.._', 'V': '..._', 'W': '.__', 'X': '_.._',
           'Y': '_.__', 'Z': '__..',
           '1': '.____', '2': '..___', '3': '...__', '4': '...._', '5': '.....',
           '6': '_....', '7': '__...', '8': '___..', '9': '____.', '0': '_____',
           ' ': ' '}
    if x in dic:
        return dic[x]


def Turn_Morse_code(s):
    s = s.upper()  # 将小写字母转换为大写字母
    num = len(s)
    Morsecode = ''
    i = 0
    for i in range(num):
        Morsecode += str(Morse_code(s[i]))
    return Morsecode


def conjecture():  # 猜数字游戏的函数
    answer = random.randint(1, 100)  # 产生的随机数范围包括下限和上限
    counter = 0
    print('请猜一猜这个整数(1—100)是多少?')
    while True:
        counter += 1
        number = input()
        if number.isdigit():  # 用number.isdigit判断字符串是否为纯数字
            number = int(number)
            if number < answer:
                print('太小了!')
            elif number > answer:
                print('太大了!')
            elif number == answer:
                print('恭喜你猜对了!')
                break
        else:
            print('请输入1至100的整数!')
    print('你总共猜了%d次' % counter)
    if counter > 7:
        print('你的智商余额明显不足')


# *变量与函数准备*
save1_name = "0"
save2_name = "0"
save3_name = "0"
save4_name = "0"
save5_name = "0"
save1_time = "0"
save2_time = "0"
save3_time = "0"
save4_time = "0"
save5_time = "0"
save1 = "0"
save2 = "0"
save3 = "0"
save4 = "0"
save5 = "0"
# 文本系统变量(好多啊)

lock2 = 0
line = "---------------------------------------------------"
# 分割线
# *变量与函数准备*

# 主循环
while True:
    # 最基础的hello world
    get, get2, get3 = input(">").split()
    if get == "print" or get == "P" or get == "P":
        print(get2)
        print(line)

    # 获取时间
    elif get == "time":
        now = datetime.datetime.now()
        print("it's", now, "now")
        print(line)

    # 字符串相连
    elif get2 == ",":
        print(get + get3)
        print(line)

    # *计算*
    elif get2 == "+":
        try:
            get = int(get)
            get3 = int(get3)
            print((get + get3))
            print(line)
        except ValueError:
            now = datetime.datetime.now()
            print('错误:输入类型错误,请输入整数')
            print(now)
            print(line)

    elif get2 == "-":
        try:
            get = int(get)
            get3 = int(get3)
            print((get - get3))
            print(line)
        except ValueError:
            now = datetime.datetime.now()
            print('错误:输入类型错误,请输入整数')
            print(now)
            print(line)

    elif get2 == "*":
        try:
            get = int(get)
            get3 = int(get3)
            print((get * get3))
            print(line)
        except ValueError:
            now = datetime.datetime.now()
            print('错误:输入类型错误,请输入整数')
            print(now)
            print(line)

    elif get2 == "/":
        try:
            get = int(get)
            get3 = int(get3)
            print((get / get3))
            print(line)
        except:
            now = datetime.datetime.now()
            print('错误:输入类型错误或除数为0,请输入不等于0的整数')
            print(now)
            print(line)

    elif get2 == "pow":
        try:
            get = int(get)
            get3 = int(get3)
            print(pow(get, 1.0 / get3))
            print(line)
        except ValueError:
            now = datetime.datetime.now()
            print('错误:输入类型错误,请输入整数')
            print(now)
            print(line)

    elif get2 == "^2":
        try:
            get = int(get)
            print((get * get))
            print(line)
        except ValueError:
            now = datetime.datetime.now()
            print('错误:输入类型错误,请输入整数')
            print(now)
            print(line)
    # *计算*

    # 获取信息
    elif get == "information":
        print("------*Sunrise language*------\n版本号:beta0.1 最晚更新时间:2022/11\n出品人员:\n策划:小米\n编程:小米\n------ "
              "荣誉出品------")

        # 游戏列表
    elif get == "game" or get2 == "game" or get3 == "game":
        print(
            "游戏列表:①猜拳游戏:和电脑进行激动的猜拳比赛![1]\n        ②井字棋:想玩一盘井字棋吗?        [2]\n        ③猜数字:猜出电脑想的数字!        [3]\n*输入“[]”内的字符进入游戏,输入“exit”退出游戏系统")
        print(line)
        game_get = input("->")
        if game_get == "3":
            print(
                "感谢cartes1us大佬!转载地址喵kill2013110/article/details/112721962")
            print('>>>>>====-游戏开始-====<<<<<')
            conjecture()
            while True:
                option = input('还想再玩一次吗?(回答y或n)\n')
                yes = 'y'
                no = 'n'
                if option == yes:
                    conjecture()
                elif option == no:
                    break
                else:
                    print('你的回答电脑无法识别!\n')
            print('>>>>>====-游戏结束-====<<<<<')
            # 感谢cartes1us大佬

        # 猜拳游戏
        elif game_get == "1":
            print("欢迎来到猜拳游戏!")
            print("输入“1”出剪刀,输入“2”出石头,输入“3”出布")
            print("*请勿输入除数字以外的字符*")
            game_1_get = int(input("->"))
            # 获取玩家和电脑的输入
            game_1_get2 = random.randint(1, 3)
            # 玩家、电脑的输赢比较(1剪刀,2石头,3布)
            if game_1_get == game_1_get2:
                if_get(game_1_get2)
                print("平手")
            elif game_1_get == 1 and game_1_get2 == 2:
                if_get(game_1_get2)
                print("电脑赢了!")
            elif game_1_get == 2 and game_1_get2 == 3:
                if_get(game_1_get2)
                print("电脑赢了!")
            elif game_1_get == 3 and game_1_get2 == 1:
                if_get(game_1_get2)
                print("电脑赢了!")
            elif game_1_get == 1 and game_1_get2 == 3:
                if_get(game_1_get2)
                print("你赢了!")
            elif game_1_get == 2 and game_1_get2 == 1:
                if_get(game_1_get2)
                print("你赢了!")
            elif game_1_get == 3 and game_1_get2 == 2:
                if_get(game_1_get2)
                print("你赢了!")
            print("获取更多信息请输入“information”,退出请输入任意字符")
            game_1_get3 = input("->")
            # 游戏的相关信息
            if game_1_get3 == "information":
                print("""
            ------猜拳游戏------
            版本号:beta0.1,作者:小米
            """)
                print(line)
            else:
                print("游戏退出成功")

        elif game_get == "2":
            # Tic Tac Toe
            print("欢迎进入游戏”井字棋“\n*感谢”极度寒空“大佬")

            def drawBoard(board):
                # 打印棋盘
                # "board"是长度为10的列表,为了方便输入,忽略第一个元素board[0]

                print('\n\n\n\n')
                print('\t\t\t┌─┬─┬─┐')
                print('\t\t\t│' + board[7] + ' │' +
                      board[8] + ' │' + board[9] + ' │')
                print('\t\t\t├─┼─┼─┤')
                print('\t\t\t│' + board[4] + ' │' +
                      board[5] + ' │' + board[6] + ' │')
                print('\t\t\t├─┼─┼─┤')
                print('\t\t\t│' + board[1] + ' │' +
                      board[2] + ' │' + board[3] + ' │')
                print('\t\t\t└─┴─┴─┘')

            def inputPlayerLetter():
                # 让玩家选择棋子
                # 返回一个列表,第一个是玩家的棋子,第二个是电脑的
                letter = ''
                while not (letter == 'X' or letter == 'O'):
                    print('Do you want to be X or O(输入”X“或”O“?')
                    letter = input("->").upper()

                if letter == 'X':
                    return ['X', 'O']
                else:
                    return ['O', 'X']

            def whoGoesFirst():
                # 随机产生谁先走
                if random.randint(0, 1) == 0:
                    return 'computer'
                else:
                    return 'player'

            def playAgain():
                # 再玩一次?输入yes或y返回True
                print('Do you want to play again? (请输入”yes“或”no“)')
                return input(">").lower().startswith('y')

            def makeMove(board, letter, move):
                # 落子
                board[move] = letter

            def isWinner(bo, le):
                # 判断所给的棋子是否获胜
                # 参数为棋盘上的棋子(列表)和棋子符号
                # 以下是所有可能胜利的情况,共8种
                return ((bo[7] == le and bo[8] == le and bo[9] == le) or
                        (bo[4] == le and bo[5] == le and bo[6] == le) or
                        (bo[1] == le and bo[2] == le and bo[3] == le) or
                        (bo[7] == le and bo[4] == le and bo[1] == le) or
                        (bo[8] == le and bo[5] == le and bo[2] == le) or
                        (bo[9] == le and bo[6] == le and bo[3] == le) or
                        (bo[7] == le and bo[5] == le and bo[3] == le) or
                        (bo[9] == le and bo[5] == le and bo[1] == le))

            def getBoardCopy(board):
                # 复制一份棋盘,供电脑落子时使用
                dupeBoard = []

                for i in board:
                    dupeBoard.append(i)

                return dupeBoard

            def isSpaceFree(board, move):
                # 判断这个位置是否有子,没子返回True
                return board[move] == ' '

            def getPlayerMove(board):
                # 玩家落子
                move = ' '
                while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):
                    print('请移动你的棋子? (输入数字1-9)')
                    move = input("->")
                return int(move)

            def chooseRandomMoveFromList(board, movesList):
                # 随机返回一个可以落子的坐标
                # 如果没有所给的movesList中没有可以落子的,返回None
                possibleMoves = []
                for i in movesList:
                    if isSpaceFree(board, i):
                        possibleMoves.append(i)

                if len(possibleMoves) != 0:
                    return random.choice(possibleMoves)
                else:
                    return None

            def getComputerMove(board, computerLetter):
                # 确定电脑的落子位置
                if computerLetter == 'X':
                    playerLetter = 'O'
                else:
                    playerLetter = 'X'

                # Tic Tac Toe AI核心算法:
                # 首先判断电脑方能否通过一次落子直接获得游戏胜利
                for i in range(1, 10):
                    copy = getBoardCopy(board)
                    if isSpaceFree(copy, i):
                        makeMove(copy, computerLetter, i)
                        if isWinner(copy, computerLetter):
                            return i

                # 判断玩家下一次落子能否获得胜利,如果能,给它堵上
                for i in range(1, 10):
                    copy = getBoardCopy(board)
                    if isSpaceFree(copy, i):
                        makeMove(copy, playerLetter, i)
                        if isWinner(copy, playerLetter):
                            return i

                # 如果角上能落子的话,在角上落子
                move = chooseRandomMoveFromList(board, [1, 3, 7, 9])
                if move != None:
                    return move

                # 如果能在中心落子的话,在中心落子
                if isSpaceFree(board, 5):
                    return 5

                # 在边上落子
                return chooseRandomMoveFromList(board, [2, 4, 6, 8])

            def isBoardFull(board):
                # 如果棋盘满了,返回True
                for i in range(1, 10):
                    if isSpaceFree(board, i):
                        return False
                return True

            print('Welcome to Tic Tac Toe!')

            while True:
                # 更新棋盘
                theBoard = [' '] * 10
                playerLetter, computerLetter = inputPlayerLetter()
                turn = whoGoesFirst()
                print('The ' + turn + ' will go first.')
                gameIsPlaying = True

                while gameIsPlaying:
                    if turn == 'player':
                        # 玩家回合
                        drawBoard(theBoard)
                        move = getPlayerMove(theBoard)
                        makeMove(theBoard, playerLetter, move)

                        if isWinner(theBoard, playerLetter):
                            drawBoard(theBoard)
                            print('你赢得了游戏!')
                            gameIsPlaying = False
                        else:
                            if isBoardFull(theBoard):
                                drawBoard(theBoard)
                                print('The game is a tie!')
                                break
                            else:
                                turn = 'computer'

                    else:
                        # 电脑回合
                        move = getComputerMove(theBoard, computerLetter)
                        makeMove(theBoard, computerLetter, move)

                        if isWinner(theBoard, computerLetter):
                            drawBoard(theBoard)
                            print('电脑赢了!')
                            gameIsPlaying = False
                        else:
                            if isBoardFull(theBoard):
                                drawBoard(theBoard)
                                print('The game is a tie!')
                                break
                            else:
                                turn = 'player'

                if not playAgain():
                    break

            # 感谢“极度寒空”大佬
            # 原文链接喵 qq_39035741 / article / details / 77101765

        # 游戏列表操作(退出与错误判定)
        elif game_get == "exit":
            print("退出")
            print(line)
        else:
            print("未查找到游戏“", game_get, "”")
            print(line)

    # 帮助系统
    elif get == "help":
        print("""
第一页/共二页
print + str + *    : 打印字符串
int1 + * + int2    : 返回两个数值计算结果
help + *           : 获取帮助
information + *    : 获取相关信息
game + *           : 打开游戏
lock + *           : 锁定操作系统
save + *           : 打开和操作stxt系统
open_stxt + *      : 打开stxt文件
url + *            : 使用默认浏览器打开网站
----输入“next”切换到下一页,输入任意字符退出帮助系统----
""")
        help_get = input("->")
        if help_get == "next":
            print("""

""")

            print(line)
        else:
            print("正在退出帮助系统......")
            print(line)

    elif get == "save":
        print("*stxt文件处理器*输入”[]“内的内容查看或编辑文本,输入任意键退出")
        # 显示文件相关信息
        if save1 == "0":
            print("[1]:暂无内容 ", save1_name, save1_time)
        else:
            print("[1]:", save1_name, save1_time)
        if save2 == "0":
            print("[2]:暂无内容 ", save2_name, save2_time)
        else:
            print("[2]:", save2_name, save2_time)
        if save3 == "0":
            print("[3]:暂无内容 ", save3_name, save3_time)
        else:
            print("[3]:", save3_name, save3_time)
        if save4 == "0":
            print("[4]:暂无内容 ", save4_name, save4_time)
        else:
            print("[4]:", save4_name, save4_time)
        if save5 == "0":
            print("[5]:暂无内容 ", save5_name, save5_time)
        else:
            print("[5]: ", save5_name, save5_time)
        save_get = input("->")
        # 对文件们进行操作
        if save_get == "1":
            print(line, )
            print(save1)
            print("")
            print()
            print(save1_time)
            print(line)
            print("编辑[1]    重名名[2]    退出任意键")
            save_get2 = input("->")
            if save_get2 == "1":
                save1 = input("->")
                save1_time = datetime.datetime.now()
                print("成功修改文本为:", save1)
            if save_get2 == "2":
                save1_name = input("->")
                print("已成功将此文件改名为:", save1_name)
        if save_get == "2":
            print(line)
            print(save2)
            print("")
            print()
            print(save2_time)
            print(line)
            print("编辑[1]    重名名[2]    退出任意键")
            save_get2 = input("->")
            if save_get2 == "1":
                save2 = input("->")
                save2_time = datetime.datetime.now()
                print("成功修改文本为:", save2)
            if save_get2 == "2":
                save2_name = input("->")
                print("已成功将此文件改名为:", save2_name)
        if save_get == "3":
            print(line)
            print(save3)
            print(save3_time)
            print(line)
            print("编辑[1]    重名名[2]    退出任意键")
            save_get2 = input("->")
            if save_get2 == "1":
                save3 = input("->")
                save3_time = datetime.datetime.now()
                print("成功修改文本为:", save3)
            if save_get2 == "2":
                save3_name = input("->")
                print("已成功将此文件改名为:", save3_name)
        if save_get == "4":
            print(line)
            print(save4)
            print("")
            print()
            print(save4_time)
            print(line)
            print("编辑[1]    重名名[2]    退出任意键")
            save_get2 = input("->")
            if save_get2 == "1":
                save4 = input("->")
                save4_time = datetime.datetime.now()
                print("成功修改文本为:", save4)
            if save_get2 == "2":
                save4_name = input("->")
                print("已成功将此文件改名为:", save4_name)
        if save_get == "5":
            print(line)
            print(save5)
            print("")
            print()
            print(save5_time)
            print(line)
            print("编辑[1]    重名名[2]    退出任意键")
            save_get2 = input("->")
            if save_get2 == "1":
                save5 = input("->")
                save5_time = datetime.datetime.now()
                print("成功修改文本为:", save5)
            if save_get2 == "2":
                save5_name = input(">")
                print("已成功将此文件改名为:", save5_name)
    # 锁定系统
    elif get == "lock":
        print("请输入密码(输入*忽略)")
        lock = input("->")
        # 喵循环,一直要求用户输入密码
        while True:
            print("""
██╗      ██████╗  ██████╗██╗  ██╗
██║     ██╔═══██╗██╔════╝██║ ██╔╝
██║     ██║   ██║██║     █████╔╝ 
██║     ██║   ██║██║     ██╔═██╗ 
███████╗╚██████╔╝╚██████╗██║  ██╗
╚══════╝ ╚═════╝  ╚═════╝╚═╝  ╚═╝
系统已锁定,请输入正确的密码
""")
            print(big_line)
            lock2 = input("->")
            # 直到用户输入正确密码,退出循环
            if lock2 == lock or lock == "*":
                break

    # 一堆的python内置函数
    elif get == "bin":
        get2 = int(get2)
        print(bin(get2))
        print(line)

    elif get == "oct":
        get2 = int(get2)
        print(oct(get2))
        print(line)

    elif get == "hex":
        get2 = int(get2)
        print(hex(get2))
        print(line)

    elif get == "abs":
        get2 = int(get2)
        print(abs(get2))
        print(line)

    elif get == "round":
        get2 = int(get2)
        print(round(get2))
        print(line)

    elif get == "picture":
        print("*输入“[]”内的内容打开图片,输入任意键退出图片查看系统*\n[1]狗\n[2]鸡\n[3]蝴蝶\n[4]末影龙\n[5]骆驼")
        # 判断用户输入,显示对应图片
        picture_get = input("->")
        if picture_get == "1":
            print("""
       .-~~~~-.
      / __     \
     | /  \  /  `~~~~~-.
     ||    |  0         @
     ||    |  _.        |
     \|    |   \       /
      \    /  /`~~~~~~`
      ('--'""`)
""")
            print(line)
        if picture_get == "2":
            print("""
   __
_/o \
/_    |               | /
W\  /              |
   \ \  __________||//|/
    \ \/         /|/-//-
     |     -----  // --
     |      -----   /-
     |     -----    /
      \            /
        \_/  \___/
          \  //
           |||
           |||
          Z_>>
""")
            print(line)
        if picture_get == "3":
            print("""
  / `._                     _.' \
     ( @ : `.                 .' : @ )
      \  `.  `.  ._     _.  .'  .'  /
       \;' `.  `.  \   /  .'  .' `;/
        \`.  `.  \  \_/  /  .'  .'/
         ) :-._`. \ (:) / .'_.-: (
         (`.....,`.\/:\/.',.....')
          >------._|:::|_.------<
         / .'._>_.-|:::|-._<_.'. \
         |o _.-'_.-^|:|^-._`-._ o|
         |`'   ;_.-'|:|`-._;   `'|
         ".o_.-' ;."|:|".; `-._o."  
           ".__."   \:/   ".__."
""")

            print(line)
        if picture_get == "4":
            print("""
                         \ /v\     /v\/
                          \><\   /><\ /><\/>")
        if xiao_mi_get == "2":
            print("谢谢!:)")
        elif xiao_mi_get == "1":
            print("对不起,我会继续努力的!:(")

    elif get == "F" or get == "function":
        function_get = int(input("->y = x*"))
        x = np.arange(-10, 10, 0.1)
        y = function_get * x
        plt.xlabel('x')
        plt.ylabel('y')
        plt.title("function")
        plt.plot(x, y)
        plt.show()

    elif get == "url":
        # 默认浏览器打开指定地址
        print("请输入网址")
        url_get = input("->www.")
        webbrowser.open("www." + url_get)
        print("网站打开成功")

    # 错误提示
    else:
        now = datetime.datetime.now()
        print("错误:未发现函数", get)
        print(now)
        print(line)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页