猫史档案馆


【Python作品分享】源码背包(解锁版)【作品秀】

用户:余宏松余宏松查看:1 回复:1 评论:1 创建时间:2021-04-17T16:06:27


【作品展示】

center_image

 

【作品介绍】

我的作业

 

【作品源代码】

import turtle
myPen = turtle.Pen()
screen = turtle.Screen()
myPen.pencolor('light sky blue')

# 9个点的坐标
pos = [
    [-100,100],[0,100],[100,100],
    [-100,0],[0,0],[100,0],
    [-100,-100],[0,-100],[100,-100]
]

# 循环遍历列表,绘制出9个点
for i in pos:
    myPen.penup()
    myPen.goto(i)
    myPen.pendown()
    myPen.dot(40)

answer = [7,8,5,6,1,2]
flag = True
myPen.pencolor('deep sky blue')
myPen.pensize(3)
myPen.penup()

for i in answer:
    num = int(screen.textinput('输入', '请输入一个数字'))
    if num != i:
        flag = False
    choice = pos[num - 1]
    myPen.goto(choice)
    myPen.pendown()
    myPen.dot(20)

if flag:
    print('解锁成功')
    bag = ['望远镜', '源码手表', '爱心气球']

    # 操作菜单
    print('--------------------------')
    print('输入数字,执行选项中的操作~')
    print('1、添加一个道具')
    print('2、查找一个道具')
    print('3、修改一个道具')
    print('4、删除一个道具')
    print('5、退出背包')
    print('--------------------------')

    while True:
        # 输入选项
        print(bag)
        option = input('输入一个操作选项吧:')

        # 添加道具
        if option == '1':
            add_name = input('请输入要添加的新道具吧:')
            bag.append(add_name)

        # 查找道具
        elif option == '2':
            search_name = input('需要查找哪件道具呀?')
            if search_name in bag:
                print(search_name, '在源码背包中呦~')
            else:
                print('源码背包中没有', search_name)

        # 修改道具
        elif option == '3':
            search_name = input('需要修改哪件道具呀?')
            if search_name in bag:
                change_name = input('道具修改后的名字是什么呢?')
                search_place = bag.index(search_name)
                bag[search_place] = change_name
            else:
                print('源码背包中没有', search_name)

        # 删除道具
        elif option == '4':
            print('删除道具')

        # 退出背包
        elif option == '5':
            print('退出背包')
            break

        else:
            print('输入内容有议,请重新操作!')

        print('--------------------------')


else:
    print('解锁失败')
turtle.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
余宏松余宏松

Y(^o^)Y

点赞1


评论