chore: 添加项目基础结构和示例代码

- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
This commit is contained in:
sairate 2025-07-05 09:36:00 +08:00
commit 7df250638d
194 changed files with 2034 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

8
.idea/PythonV1_V2.iml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,15 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="numpy" />
<item index="1" class="java.lang.String" itemvalue="pyzero" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

10
.idea/material_theme_project_new.xml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="619417ac:197d81ada1e:-7fc2" />
</MTProjectMetadataState>
</option>
</component>
</project>

4
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PythonV1_V2.iml" filepath="$PROJECT_DIR$/.idea/PythonV1_V2.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Binary file not shown.

View File

@ -0,0 +1,9 @@
food_choice = input("1.吃水果2.吃牛排3.吃零食。请选择:")
if food_choice == "1":
print("早餐吃水果补充维C快成长")
elif food_choice == "2":
print("早餐吃牛排,一定要适量")
elif food_choice == "3":
print("早饭吃零食,非常不健康")
else:
print("输入错误,请重新输入")

View File

@ -0,0 +1,9 @@
print("幸运的小冒险家:")
print("恭喜您被选中参加2023年世界级最无聊之数豆子锦标赛。")
answer = input("您是否愿意参加比赛接收挑战呢?请回答''或者''")
if answer == "":
print("加油,期待你成为无聊之王!")
elif answer == "":
print("机不可失时不再来,真的不想想了吗?")
else:
print("题都没读懂,失去参赛资格!")

View File

@ -0,0 +1,33 @@
print("亲爱的上帝朋友们:")
print("为回馈大家对本店的大力支持本店将开展为期3天的促销活动。")
print("我们将指派P仔为促销折扣官。")
print()
kind = input("您要查询的品类是?请输入'水果'或者'肉类'或者'零食'")
if kind == "水果" :
answer = input("查询'水果种类'还是'折扣力度'")
if answer == "水果种类" :
print("水果种类有:香蕉,苹果,桃子,樱桃,榴莲,李子")
elif answer == "折扣力度" :
print("全场水果九折优惠")
else:
print("...没理解您的问题,请重新查询...")
elif kind == "肉类" :
answer = input("查询'肉类种类'还是'折扣力度'")
if answer == "肉类种类" :
print("肉类种类有:猪五花,羊肉,牛排,鸡腿,鸡翅,鱼肉")
elif answer == "折扣力度" :
print("全场肉类八折优惠")
else:
print("...没理解您的问题,请重新查询...")
elif kind == "零食":
answer = input("查询'零食种类'还是'折扣力度'")
if answer == "零食种类" :
print("零食种类有:酸奶,黄桃干,巧克力威化,奥利奥,薯片,鱿鱼丝,AD钙奶")
elif answer == "折扣力度" :
print("全场零食七折优惠")
else:
print("...没理解您的问题,请重新查询...")
else:
print("其余商品原价出售")
print()
print("查询完毕,祝您购物愉快,欢迎随时来找我玩哟~")

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

View File

@ -0,0 +1,18 @@
import random
price = int(input("请输入您购买的商品总额,判定您是否有抽奖资格:"))
if price >= 300:
print("......开始抽奖......")
number = random.randint(1,10)
print(number)
if number == 1:
print("一等奖:编程机器人")
elif number == 2 or number == 3:
print("二等奖:超大毛绒玩具熊")
elif number == 4 or number == 5:
print("三等奖:磁悬浮地球仪")
elif number == 6 or number == 7:
print("四等奖:三阶魔方")
else:
print("参与奖:抽纸一包")
else:
print(f"总价{price}不符合抽奖要求")

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

View File

@ -0,0 +1,14 @@
while True:
username = input('请输入您的代号:')
password = input('请输入您的密码:')
# 检查用户名和密码是否正确
if username == '007' and password == '妈咪妈咪哄':
print('登录成功!')
break
if username != '007':
print('代号错误!请重新输入')
continue
if password != '妈咪妈咪哄':
print('密码记错了吧!请重新输入')
print('特工007欢迎回家')

View File

@ -0,0 +1,6 @@
guess_number = 56
while True:
num = int(input("猜猜我心里的数字是(1-100之间)"))
if num == guess_number:
break
print("终于找到你了!")

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 KiB

View File

@ -0,0 +1,25 @@
# 请在这里编写代码
name = ['黄昏', '黎明', '007', '萧炎', '唐三']
task = ['潜入敌国获取情报',
'采摘生长在天山的雪莲花',
'给隔壁出差李阿姨家的喵喵加粮',
'营救被扣押的人质',
'破解电脑系统获取目标数据']
# 007通过密钥2获取相应的任务信息(访问列表元素)
task_007 = task[2]
print("007的特工任务" + task_007)
print()
# 获取特工列表长度
print('共有特工' + str(len(name)) + '')
# 长官要看到每位特工的任务详情
for i in range(len(name)):
print(name[i] + "的特工任务:" + task[i])
print()
# “萧炎”和“唐三”特工合作完成任务(列表的切片)
task_together = task[3:]
print(task_together)

View File

@ -0,0 +1,8 @@
#请在这里编写代码
fruit = ["苹果", "香蕉", "橙子", "草莓", "葡萄", "樱桃"]
fruit1 = fruit[1:4]
fruit2 = fruit[::2]
print(fruit1)
print(fruit2)

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

View File

@ -0,0 +1,28 @@
#请在这里编写代码
name = ['黄昏','黎明','007','萧炎','唐三']
task = ['潜入敌国获取情报',
'采摘生长在天山的雪莲花',
'给隔壁出差李阿姨家的喵喵加粮',
'营救被扣押的人质',
'破解电脑系统获取目标数据']
skill = input("请使用特工技能(1.跳跃2.隐匿3.射击)")
if skill == '1':
print('成功进入李阿姨的院子')
skill = input('请使用特工技能(1.跳跃2.隐匿3.射击)')
if skill == '2':
print('成功加粮')
# 方法一:删除指定元素,指定索引位置添加元素
task.pop(2)
task.insert(2,'抢回被夺走的特工名单')
# 方法二:修改列表元素
# task[2] = '抢回被夺走的特工名单'
print(task)
elif skill == '2':
print('无法进入院子')
elif skill == '3':
print('任务失败,被组织除名')
name.pop(2) # 或者name.remove('007')或者del name[2]
print(name)
else:
print('请正确输入技能编号')

View File

@ -0,0 +1,8 @@
#请在这里编写代码
animals = ["猴子", "小花猪", "蝴蝶", "豹子"]
#animals.pop()
#del animals[3]
animals.remove('豹子')
animals.insert(1,"大象")
animals.append('绵羊')
print(animals)

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 KiB

View File

@ -0,0 +1,15 @@
# 名单在争抢中被撕成两份,需要先修复特工名单
tup1 = ('黄昏','黎明','007')
tup2 = ('萧炎','唐三')
tup_all = tup1 + tup2
# 加密(字符串、切片)
key = "ay"
list_all = []
for name in tup_all:
first = name[0]
last = name[1:]
new_name = last + first + key
list_all.append(new_name)
new_tup = tuple(list_all)
print(new_tup)

View File

@ -0,0 +1,8 @@
tup = ("迪迦", "赛文", "佐菲", "戴拿")
key = "同学"
lst = []
for name in tup:
new_name = name + key
lst.append(new_name)
new_tup = tuple(lst)
print(new_tup)

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 KiB

View File

@ -0,0 +1,16 @@
# 顶级特工007写了一本《特工密语大全》在特工中广为流传他会实时对书中的内容进行修改
handbook = ['宫廷玉液酒,一百八一杯','你是我的兄弟','天王盖地虎,小猫抓老鼠','明月几时有,抬头自己瞅','给你点赞']
# 最近特工密语“你是我的兄弟”被敌人破解了,需要从《特工密语大全》中删除
handbook.remove('你是我的兄弟')
# 特工们的密语也需要紧跟时代,最近流行一种新的密语“不可能!绝对不可能”,要及时加入《密语大全》
handbook.append('不可能!绝对不可能')
# 接到上头通知,从前用的密语“给你点赞”要更新为“你真是泰酷辣”,需要及时更新替换
for i in range (len(handbook)):
if handbook[i] == '给你点赞':
handbook[i] = '你真是泰酷辣'
# 输出最新的《特工密语大全》
print(handbook)

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 KiB

View File

@ -0,0 +1,26 @@
# 3张藏宝图中的4个关键信息
map1 = {1:'女儿出嫁(打一字)',2:'向西走,回头看(打一方向)'}
map2 = {3:'由外西北广,于代宝玉来(打一地方)'}
map3 = {4:'一个字,八个头,里面有水不外流(打一字)'}
# 串联所有的藏宝图信息都存储在map1中
map1.update(map2)
map1.update(map3)
# 输出所有的谜题
print('''----开启宝藏的方法----
下面谜底连在一起为宝藏之谜
--------------------------''')
# 遍历字典的值,输出所有谜题
for i in map1.values():
print(i)
# 挨个询问谜底
ans1 = input('请猜测第一个谜底:')
ans2 = input('请猜测第二个谜底:')
ans3 = input('请猜测第三个谜底:')
ans4 = input('请猜测第四个谜底:')
# 如果谜底全部正确,则输出正确的藏宝地
if ans1 == '' and ans2 == '东侧' and ans3 == '庙宇' and ans4 == '':
print('''**** 恭喜你 ****
成功解开了宝藏之谜''')
print('宝藏位于:家东侧庙宇的井中')
else:
print('你所猜测的地方没有宝藏')

View File

@ -0,0 +1,8 @@
shop = { '牛奶':10, '辣条':10, '方便面':8, '火腿肠':8 }
shop['方便面'] = 4
shop['火腿肠'] = 4
print(shop)
shop['面包'] = 5
print(shop)
for i in shop:
print(i)

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 KiB

View File

@ -0,0 +1,38 @@
print('--- 欢迎进入我的私人通讯录 ---')
print('--- 1查询、修改 ---')
print('--- 2新增联系人 ---')
print('--- 3删除联系人 ---')
print('--- 4退出通讯录 ---')
phone = {'大强':'13111111111', '爸爸':'15735199988'}
# 无限循环通讯录的操作
while True:
num = int(input('请输入相关操作数字代号:'))
# 如果输入数字1则查询指定联系人电话如果联系人存在则询问是否修改联系人电话
if num == 1:
name = input('请输入联系人姓名:')
if name in phone:
print(name + ' : ' + phone[name])
if input('是否修改联系人电话YES/NO') == 'YES':
phone[name] = input('请输入联系人新电话:')
else:
print('您输入的姓名不在通讯录中!')
# 如果输入数字2则查询该联系人是否在通讯录如果不在则新建
if num == 2:
name = input('请输入联系人姓名:')
if name in phone:
print('您输入的姓名在通讯录中已存在')
print(name + ' : ' + phone[name])
else:
phone[name] = input('请输入联系人电话:')
# 如果输入数字3则删除对应联系人的键值对
if num == 3:
name = input('请输入联系人姓名:')
if name in phone:
del phone[name]
else:
print('您输入的联系人不存在')
# 如果输入数字4则跳出整个循环停止使用通讯录
if num == 4:
break
print('---- 感谢使用私人通讯录 ----')

View File

@ -0,0 +1,7 @@
pet_park = {"Tom":"鱼干","Jerry":"奶酪","Buddy":"罐头","Lucky":"骨头"}
if 'Buddy' in pet_park:
print('Buddy喜欢的食物是' + pet_park['Buddy'])
else:
print('Buddy 不在宠物乐园')
del pet_park['Tom']
print(pet_park)

View File

@ -0,0 +1,42 @@
print('--- 欢迎进入我的私人通讯录 ---')
print('--- 1查询、修改 ---')
print('--- 2新增联系人 ---')
print('--- 3删除联系人 ---')
print('--- 4退出通讯录 ---')
phone = {'大强':'13111111111', '爸爸':'15735199988'}
# 无限循环通讯录的操作
while True:
num = int(input('请输入相关操作数字代号:'))
# 如果输入数字1则查询指定联系人电话如果联系人存在则询问是否修改联系人电话
if num == 1:
name = input('请输入联系人姓名:')
if name in phone:
print(name + ' : ' + phone[name])
if input('是否修改联系人电话YES/NO') == 'YES':
phone[name] = input('请输入联系人新电话:')
else:
print('您输入的姓名不在通讯录中!')
# 如果输入数字2则查询该联系人是否在通讯录如果不在则新建
if num == 2:
name = input('请输入联系人姓名:')
if name in phone:
print('您输入的姓名在通讯录中已存在')
print(name + ' : ' + phone[name])
else:
phone[name] = input('请输入联系人电话:')
# 如果输入数字3则删除对应联系人的键值对
if num == 3:
name = input('请输入联系人姓名:')
if name in phone:
del phone[name]
else:
print('您输入的联系人不存在')
# 如果输入数字4则跳出整个循环停止使用通讯录
if num == 4:
break
# 隐藏任务选做如果输入0则可以查看完整的通讯录
if num == 0:
for key,value in phone.items():
print(key,value,sep = ':')
print('---- 感谢使用私人通讯录 ----')

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 KiB

View File

@ -0,0 +1,17 @@
import random
set1 = set()
set2 = set()
for i in range(5):
set1.add(random.randint(1,10))
set2.add(random.randint(1,10))
print(set1)
print(set2)
common = set1.intersection(set2)
print(common)
own_1 = set1.difference(set2)
print(own_1)
own_2 = set2.difference(set1)
print(own_2)
all_set = set1.union(set2)
print(all_set)

View File

@ -0,0 +1,26 @@
# 三人列出各自的好友签到表
pzai = {'马里奥','狗蛋','二丫','冠冠','卡卡'}
xiaoE = {'静静','铁柱','米粒','瞳瞳','嘟嘟'}
boks = {'小奶酪','倩倩','冠冠','卡卡','轩轩'}
# pzai和boks有一些共同的好友请找出这些共同好友防止重复邀请
common = pzai.intersection(boks)
print(common)
# 有一些是独属于pzai、boks的朋友请找出这些朋友
own_p = pzai.difference(boks)
print(own_p)
own_b = boks.difference(pzai)
print(own_b)
# 将所有人的好友都写在一张签到表上,注意不重不漏
set1 = pzai.union(boks)
all_set = set1.union(xiaoE)
print(all_set)
# 舞会的前两天,收到大家的信息,“卡卡”临时有事无法到场,“小叶子”听说活动主动报名想要参加,所以需要对签到表进行调整
all_set.remove('卡卡')
all_set.add('小叶子')
print('————签到表————')
for i in all_set:
print(i)

View File

@ -0,0 +1,5 @@
str1 = 'apple'
str2 = 'banana'
str_all = str1 + str2
set_all = set(str_all)
print(len(set_all))

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 KiB

View File

@ -0,0 +1,15 @@
'''
p仔的闹钟是个淘气鬼
每天都变着法子叫p仔起床
今天它又换了新的唤醒服务~
5次提醒后p仔终于从床上爬了起来
同学们试着用print()打印出闹钟的铃声内容吧
悄悄说一句可以自己更改铃声内容一般人我不告诉他
'''
print("懒虫,懒虫,快起床!太阳晒到屁股啦!")
print("懒虫,懒虫,快起床!太阳晒到屁股啦!")
print("懒虫,懒虫,快起床!早饭要被吃光啦!")
print("懒虫,懒虫,快起床!上学马上迟到啦!")
print("懒虫,懒虫,快起床!妈妈要来打屁股啦!")

View File

@ -0,0 +1,9 @@
'''
使用print()函数打印自我介绍可以介绍自己的姓名爱好才艺等
目的是让大家记住你记得添上恰当的注释哦
'''
print("嗨,大家好,我叫大强!") #介绍自己的姓名
print("我是一个真ikun喜欢唱跳rap和篮球。") #介绍自己的爱好
print("music~") #开始展示
print("┗|O|┛")

View File

@ -0,0 +1,11 @@
'''
(1)使用print函数,打印出这个4行绕口令
(2)在程序的最开始添加注释介绍绕口令的题目捉兔
(3)将这个程序保存下来
'''
#《捉兔》
print('一位爷爷他姓顾,上街打醋又买布')
print('买了布,打了醋,回头看见鹰抓兔')
print('放下布,搁下醋,上前去追鹰和兔')
print('飞了鹰,跑了兔,打翻醋,醋湿布')

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 KiB

View File

@ -0,0 +1,35 @@
# 字典王者show英雄和台词一一对应
actor = {'钟馗':'沧海桑田,唯混沌与破烂源源不断',
'李白':'将进酒,杯莫停',
'甄姬':'人家抒发哀伤时,不要随便破坏氛围好吗?',
'百里守约':'路过草丛的熟人,以子弹礼貌招呼!',
'':'比任何对手都强,乃人生最大的烦恼'}
for i in range(len(actor)):
key = input('*欢迎今天到场的英雄*')
if key in actor.keys():
print(actor[key])
else:
print('报幕错误show搞砸了')
break
# 元组:王者队伍初组成(五人一队,英雄可重复选用,英雄选定不可更改)
team1 = ('钟馗','李白','百里守约','甄姬','项羽')
team2 = ('周瑜','曹操','鲁班七号','','妲己')
# 列表LiBai和Kai同台竞技
LiBai = ['侠客行','将进酒','神来之笔','青莲剑歌']
Kai = ['修罗之魂','极刃风暴','回旋之刃','不灭魔躯']
# 集合:化妆舞会好友圈
my_set = set()
while True:
choice = input('请选择你的操作1.关注2.取关3.退出好友圈:')
if choice == '1':
in_name = input('请问你要关注谁:')
my_set.add(in_name)
if choice == '2':
out_name = input('请问你要取关谁:')
my_set.remove(out_name)
if choice == '3':
break
print(my_set)

View File

@ -0,0 +1,19 @@
'''珠宝商人
假设你是一家珠宝店的老板用名为 jewelry 的字典存储了珠宝的相关信息现在你想要查看一款珠宝的价格请编写一个程序输出该珠宝的价格
编写一段代码要求如下
已知 jewelry={"项链":1000,"戒指":2000,"手链":1500}
(1) 输入要查价格的珠宝名称并存储在 name 变量中
(2) price 变量存储查询到的价格
(3) 输出'珠宝名称'的价格是'××'
'''
jewelry = {"项链": 1000, "戒指": 2000, "手链": 1500}
name = input("请输入要查价格的珠宝名称:")
price = jewelry[name]
print(name + "的价格是" + str(price))

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 KiB

View File

@ -0,0 +1,33 @@
'''请帮炸鸡店老板做一个点餐系统店内的商品、价格已经存储在menu字典中输入商品名称和数量打印顾客的小票算出消费总额。
已知
menu = {'香辣鸡腿堡':19.5,'劲爆鸡米花':12,'黄金鸡块':12.5,'香辣鸡翅':12.5,'香甜玉米杯':9,'醇香土豆泥':7.5,'薯条':9,'秘汁全鸡':29.9,'百事可乐':8.5}
提示如下
(1) 输出商品菜单 menu
(2) 创建空字典 total 创建变量 price初始化为0
(3) 输入购买的商品名称数量
(4) 更新商品总额 price
(5) 将购买的商品及数量添加到字典 total
(6) 输出购物小票 total输出消费总额 price
'''
menu = {'香辣鸡腿堡':19.5,'劲爆鸡米花':12,'黄金鸡块':12.5,'香辣鸡翅':12.5,
'香甜玉米杯':9,'醇香土豆泥':7.5,'薯条':9,'秘汁全鸡':29.9,'百事可乐':8.5}
print(menu)
total = {}
price = 0
while True:
food = input('请输入商品名称:')
num = int(input('请输入商品数量:'))
price = price + menu[food] * num
total[food] = num
print(total)
print(price)

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 KiB

View File

@ -0,0 +1,10 @@
# 来我的地盘,说我的话(进制转换器)
import random
print('这里是二进制部落。来我的地盘,说我的话!')
question = random.randint(1,100)
answer = input(f'十进制数{question}转换为:')
if answer == bin(question):
print('亲爱的友人,欢迎来到二进制部落')
else:
print('你在胡言乱语什么!来人,把他赶出去!')

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,26 @@
import turtle as t
def side3():
for i in range(3):
t.forward(80)
t.left(120)
def side4():
for i in range(4):
t.forward(40)
t.left(90)
t.setup(960,720)
t.bgpic('starbg.png')
t.pensize(5)
t.fillcolor('yellow')
t.begin_fill()
for i in range(5):
side3()
t.forward(80)
side4()
t.goto(0,0)
t.left(72)
t.end_fill()
t.done()

View File

@ -0,0 +1,9 @@
import turtle as t
def side6():
for i in range(6):
t.forward(100)
t.right(60)
for i in range(6):
side6()
t.right(60)
t.done()

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 KiB

View File

@ -0,0 +1,9 @@
import turtle as t
def side6():
for i in range(6):
t.forward(100)
t.right(60)
for i in range(6):
side6()
t.right(60)
t.done()

View File

@ -0,0 +1,15 @@
'''加法计算器
制作一个加法计算器将加数1加数2作为参数返回计算结果
编写一段代码要求如下
(1) 定义有参函数
(2) 返回计算结果
(3) 输出函数的返回值'''
def my_add(a,b):
c = a + b
return c
print(my_add(2,3))

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 KiB

View File

@ -0,0 +1,29 @@
import turtle as t
import colorsys
# 绘制平行四边形
def pingxing():
for j in range(2):
t.forward(100)
t.right(60)
t.forward(200)
t.right(120)
t.tracer(10)
t.bgcolor('black')
t.pensize(3)
h = 0
while True:
c = colorsys.hsv_to_rgb(h,1,1)
h += 0.005
if h > 1 :
h = 0
t.pencolor(c)
t.fillcolor('black')
t.begin_fill()
pingxing()
t.end_fill()
t.right(12)
t.done()

View File

@ -0,0 +1,59 @@
'''选择绘制五角星、三角形、正方形或者线条等函数,用相同的方法完成自己的炫彩动图。'''
import turtle as t
import colorsys
# 绘制线条
def line():
t.forward(200)
t.forward(-200)
# 绘制三角形
def side3():
for i in range(3):
t.fd(100)
t.lt(120)
# 绘制正方形
def side4():
for i in range(4):
t.fd(100)
t.lt(90)
# 绘制五角星
def star():
for i in range(5):
t.fd(100)
t.rt(144)
# 绘制平行四边形
def pingxing():
for j in range(2):
t.fd(100)
t.rt(60)
t.fd(200)
t.rt(120)
t.tracer(10)
t.bgcolor('black')
t.pensize(3)
h = 0
while True:
c = colorsys.hsv_to_rgb(h, 1, 1)
h += 0.005
if h > 1:
h = 0
t.pencolor(c)
t.fillcolor('black')
t.begin_fill()
star() # 调用上述任一函数绘制基础图案即可
t.end_fill()
t.rt(12)
t.done()

View File

@ -0,0 +1,29 @@
'''
课后作业二升级版视觉漩涡
将上节课的作品视觉漩涡进行升级添加渐变色加快绘制速度'''
import turtle as t
import colorsys
def side4(length):
for i in range(4):
t.forward(length)
t.left(90)
t.tracer(10)
t.speed(0)
t.screensize(400,300,'black') # 初始化背景尺寸、颜色
length = 5 # 初始化第一个正方形的边长为5
h = 0
for i in range(300):
c = colorsys.hsv_to_rgb(h,1,1)
t.pencolor(c) # 初始化画笔颜色
h += 0.005
if h > 1 :
h = 0
side4(length)
t.left(3)
length += 1
t.done()

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 KiB

View File

@ -0,0 +1,18 @@
import random
def choujiang():
lucky_num = random.randint(1,20) # 随机生成幸运数字1~20
num = int(input('请从1到20之间选择一个数字进行抽奖'))
if num == lucky_num: # 判断是否中奖
print('天选幸运儿恭喜你抽中大奖——狂欢夜当晚0元购')
else:
print("幸运数字" + str(lucky_num))
print('再接再厉!后面的题目还在等着你')
right = int(input('共20题你答对了多少道题'))
if right > 5:
print('呱唧呱唧!获得抽奖机会!')
choujiang() # 开始抽奖
else:
print('很遗憾,没有获得抽奖机会,再接再厉!')

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 KiB

View File

@ -0,0 +1,35 @@
# 同盟集结
import tkinter as tk # 导入tkinter库
# 检验答案,返回结果
def check_answer():
answer = var.get()
if answer == "HTML":
result_label.config(text="恭喜你获得考验资格,你敢接受挑战吗?")
else:
result_label.config(text="很遗憾,下次有缘再见")
# 创建主窗口
root = tk.Tk() # 创建主窗口对象起名为root
root.title("同盟集结") # 配置窗口标题
root.geometry('400x200+400+400') # 设置窗口大小
# 出题
question_label = tk.Label(root, text="以下哪个选项不是编程语言?")
question_label.pack()
# 设置单选按钮
var = tk.StringVar()
option_1 = tk.Radiobutton(root, text="Python", variable=var, value="Python")
option_2 = tk.Radiobutton(root, text="HTML", variable=var, value="HTML")
option_1.pack()
option_2.pack()
# 创建提交按钮
tijiao_button = tk.Button(root, text="提交答案", command=check_answer)
tijiao_button.pack()
# 创建结果标签
result_label = tk.Label(root, text="")
result_label.pack()
# 运行主循环,等待用户交互
root.mainloop()

View File

@ -0,0 +1,50 @@
'''【课后作业要求】
给题目再添加两个选项如图:
以下哪个选项不是编程语言
A.Python
B.HTML
C.Scratch
D.C++
'''
import tkinter as tk # 导入tkinter库
def check_answer(): # 检验答案,返回结果
answer = var.get()
if answer == "HTML":
result_label.config(text="恭喜你获得考验资格,你敢接受挑战吗?")
else:
result_label.config(text="很遗憾,下次有缘再见")
# 创建主窗口
root = tk.Tk() # 创建主窗口对象起名为root
root.title("同盟集结") # 配置窗口标题
root.geometry('400x200') # 设置窗口大小
# 出题
question_label = tk.Label(root, text="以下哪个选项不是编程语言?")
question_label.pack()
# 设置单选按钮
var = tk.StringVar()
option_1 = tk.Radiobutton(root, text="Python", variable=var, value="Python")
option_2 = tk.Radiobutton(root, text="HTML", variable=var, value="HTML")
option_3 = tk.Radiobutton(root, text="Scratch", variable=var, value="Scratch")
option_4 = tk.Radiobutton(root, text="C++", variable=var, value="C++")
option_1.pack()
option_2.pack()
option_3.pack()
option_4.pack()
# 创建提交按钮和结果标签
tijiao_button = tk.Button(root, text="提交答案", command=check_answer) # 提交按钮的创建
tijiao_button.pack()
result_label = tk.Label(root, text="") # 结果标签的创建
result_label.pack()
# 运行主循环,等待用户交互
root.mainloop()

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 KiB

View File

@ -0,0 +1,50 @@
'''【课后作业要求】
给题目再添加两个选项如图:
以下哪个选项不是编程语言
A.Python
B.HTML
C.Scratch
D.C++
'''
import tkinter as tk # 导入tkinter库
def check_answer(): # 检验答案,返回结果
answer = var.get()
if answer == "HTML":
result_label.config(text="恭喜你获得考验资格,你敢接受挑战吗?")
else:
result_label.config(text="很遗憾,下次有缘再见")
# 创建主窗口
root = tk.Tk() # 创建主窗口对象起名为root
root.title("同盟集结") # 配置窗口标题
root.geometry('400x200') # 设置窗口大小
# 出题
question_label = tk.Label(root, text="以下哪个选项不是编程语言?")
question_label.pack()
# 设置单选按钮
var = tk.StringVar()
option_1 = tk.Radiobutton(root, text="Python", variable=var, value="Python")
option_2 = tk.Radiobutton(root, text="HTML", variable=var, value="HTML")
option_3 = tk.Radiobutton(root, text="Scratch", variable=var, value="Scratch")
option_4 = tk.Radiobutton(root, text="C++", variable=var, value="C++")
option_1.pack()
option_2.pack()
option_3.pack()
option_4.pack()
# 创建提交按钮和结果标签
tijiao_button = tk.Button(root, text="提交答案", command=check_answer) # 提交按钮的创建
tijiao_button.pack()
result_label = tk.Label(root, text="") # 结果标签的创建
result_label.pack()
# 运行主循环,等待用户交互
root.mainloop()

View File

@ -0,0 +1,38 @@
'''【课后作业要求】
挑战一
运用学到的知识对作品进行如下调整
1.设置窗口为宽度可调整高度不可调整
2.设置标签字体为宋体
3.设置标签背景色黄任选一
黑色blackbg="black"
红色redbg="red"
黄色yellowbg="yellow"
'''
import tkinter as tk
import time
root = tk.Tk()
root.title('大聪明的时钟')
root.geometry('400x80+400+400')
root.resizable(width=True,height=False)
def update_clock():
now = time.strftime('%H:%M:%S')
label.config(text=now)
root.after(1000,update_clock)
label = tk.Label(text='',font=('宋体',60),fg='blue',bg='yellow')
label.pack()
update_clock()
root.mainloop()

View File

@ -0,0 +1,38 @@
'''挑战二:
运用学到的知识实现如图所示效果
提示
1. 创建名言标签并配置在窗口中
2. 设置合适的窗口尺寸或者尝试使用默认参数'''
# 导入tkinter、time库
import tkinter as tk
import time
# 创建主窗口
root = tk.Tk()
root.title('大聪明的时钟')
root.geometry()
root.resizable(width=False,height=False)
# 创建时间标签
label = tk.Label(text='',font=('微软雅黑',60),fg='blue')
label.pack()
# 创建名言标签
label_text = tk.Label(text='一寸光阴一寸金,寸金难买寸光阴',font=('微软雅黑',30),fg='black')
label_text.pack()
# 定义更新时间的函数
def update_clock():
now = time.strftime('%H:%M:%S')
label.config(text=now)
root.after(1000,update_clock) # 每1秒1000毫秒调用一次update_clock函数
# 更新时间
update_clock()
# 运行主循环,等待用户交互
root.mainloop()

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -0,0 +1,25 @@
'''
课后作业要求
别出心裁的信件
P仔的小学弟博克斯最近很烦恼他跟同桌莱丝吵架了不知道该怎么和好请帮博克斯制作一封独特的二维码信件向莱丝表达歉意
小小建议
1. 可以跳转到道歉的图片或者逗莱丝开心的图片
2. 可以选用有纪念意义的照片作为背景图
3. 其他可选参数自行设置无标准答案'''
from MyQR import myqr
myqr.run(
words="Sorry!", # 跳转到的页面待定(必须是英文字符串)
version = 7, # 二维码版本
level = 'Q', # 纠错等级“H”表示最高等级
picture = 'budinggou.gif', # 指定背景图片路径
colorized = True, # 是否彩色二维码
contrast = 1.2, # 对比度,根据需求调整
brightness = 0.9, # 亮度,根据需求调整
save_name = '作业.gif',
)

View File

@ -0,0 +1,12 @@
from MyQR import myqr
myqr.run(
words="Hello, World!", # 跳转到的页面待定(必须是英文字符串)
version = 5, # 二维码版本
level = 'H', # 纠错等级“H”表示最高等级
picture = 'budinggou.gif', # 指定背景图片路径
colorized = True, # 是否彩色二维码
contrast = 1.0, # 对比度,根据需求调整
brightness = 1.0, # 亮度,根据需求调整
save_name = '身份二维码_小米.gif',
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 KiB

View File

@ -0,0 +1,16 @@
#导入turtle模块起别名t
import turtle as t
#画第一条边
t.forward(100) #画边长为100的线段
t.left(120) #原地左转120度
#画第二条边
t.forward(100) #画边长为100的线段
t.left(120) #原地左转120度
#画第三条边
t.forward(100) #画边长为100的线段
t.left(120) #原地左转120度
t.done()

View File

@ -0,0 +1,12 @@
import turtle as t
t.forward(100) # 画第一条边
t.right(90) # 右转90°
t.forward(100) # 画第二条边
t.right(90) # 右转90°
t.forward(100) # 画第三条边
t.right(90) # 右转90°
t.forward(100) # 画第四条边
t.right(90) # 右转90°
t.done() # 停止画笔绘制,但绘图窗体不关闭

Some files were not shown because too many files have changed in this diff Show More