猫史档案馆


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

用户:函数Chara函数Chara查看:3 回复:5 评论:3 创建时间:2020-02-02T14:15:23


【作品展示】

center_image

 

【作品介绍】

Python shell

 

【作品源代码】

code = None
while True:
    code = input(">>>")
    exec(code)

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
wrmdcxywrmdcxy

如果输入错误代码呢

点赞0


评论


wrmdcxywrmdcxy

while True:
    code=input('>>>')
    try:
        exec(code)
    except Exception as e:
        #去掉前后括号,让输出更专业
        e=repr(e).replace('("',':')
        e=e.replace('",)','')
        print(e)

点赞0


评论


函数Chara函数Chara

code = None
class Errorr(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)
while True:
    code = input(">>>")
    try:
        exec(code)
    expect:
        raise Errorr("代码有误。")
    finally:
        continue

点赞0


评论


星空之忆星空之忆

是exec函数啊

点赞0


评论


cool-creepercool-creeper

https://shequ.cod喵/community/256550这个是我用小号编的新版

点赞0


评论