小学课后服务 Python少儿编程 提高篇:13-魔术纸牌2 课件 (26张PPT)

资源下载
  1. 二一教育资源

小学课后服务 Python少儿编程 提高篇:13-魔术纸牌2 课件 (26张PPT)

资源简介

(共26张PPT)
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
少儿编程课
魔术纸牌(二)
格式化字符串
%s:输出字符串。
%d:输出整型。
用来告诉程序以什么格式输出内容。
a = 'Hello'
print('%s,Jack!' % a)
a = ['Hello', 'Jack']
print('%s,%s!' %(a[0],a[1]))
a = 1
print('%d2345' % a)
a = 1
b = 2
print('%d%d345' % (a, b))
运行结果:
Hello,Jack!
Hello,Jack!
运行结果:
12345
12345
choice
选 择
sample
样 本
choose
选 择
魔术图解
发牌
观众选牌
收牌
发牌
观众选牌
收牌
发牌
观众选牌
收牌
发牌
找出被选中的牌
完成收牌模块
收牌顺序
每次收牌时,含有被选中牌的那一列纸牌,总是被放在三列纸牌的中间位置。
所有收牌顺序
第1列在中间时:
2、1、3或3、1、2
第2列在中间时:
1、2、3或3、2、1
第3列在中间时:
1、3、2或2、3、1
当观众选定一张纸牌时,收牌顺序有两种。
例如,观众选择的纸牌位于第2列中,则收牌顺序可以为1、2、3或3、2、1。
根据输入值的不同,共有六种收牌方式:
完成收牌模块
列表的计算
运行结果:
['a', 'b', 'c', 'd', 'e']
列表的相加:
a = ['a', 'b', 'c']
b = ['d', 'e']
print(a + b)
汇总收牌顺序
a = list2 + list1 + list3
b = list3 + list1 + list2
choose1 = [a, b] #纸牌在第1列中时,两种收牌结果
c = list1 + list2 + list3
d = list3 + list2 + list1
choose2 = [c, d] #纸牌在第2列中时,两种收牌结果
e = list1 + list3 + list2
f = list2 + list3 + list1
choose3 = [e, f] #纸牌在第3中列时,两种收牌结果
汇总收牌顺序
if条件语句
x = 0
if x > 0:
print(x, "是正数")
elif x < 0:
print(x, "是负数")
elif x == 0:
print(x, "是零")
运行结果:
0 是零
choice指令
choice():返回列表或字符串的随机项。
运行结果:
不确定,随机
import random
a = 'abcde'
b = '12345'
list1 = [a, b]
list2 = ['a', 'b']
list3 = [list1, list2]
print(random.choice(a))
print(random.choice(b))
print(random.choice(list1))
print(random.choice(list2))
print(random.choice(list3))
根据输入值收牌
choose = int(input('你选择的牌在第几列:'))
if choose == 1:
list = (random.choice(choose1)) #选择的牌在第1列时,从两种收牌顺序中随机一种
elif choose == 2:
list = (random.choice(choose2)) #选择的牌在第2列时,从两种收牌顺序中随机一种
else:
list = (random.choice(choose3)) #选择的牌在第3列时,从两种收牌顺序中随机一种
print(list)
根据输入值收牌
反思总结
复制发牌代码
对已经写过的发牌代码进行复制。
list1 = []
list2 = []
list3 = []
for i in range(7):
list1.append(list[3 * i])
list2.append(list[3 * i + 1])
list3.append(list[3 * i + 2])
print(list1)
print(list2)
print(list3)
完成发牌模块
魔术图解
发牌
观众选牌
收牌
发牌
观众选牌
收牌
发牌
观众选牌
收牌
发牌
找出被选中的牌
完成循环模块
for i in range(3):
a = list2 + list1 + list3
b = list3 + list1 + list2
choose1 = [a, b]
......
print(list1)
print(list2)
print(list3)
print('我猜出来了,你选择的牌是%s! ' % list2[3]) #输出观众选择的纸牌
完成循环模块
反思总结

展开更多......

收起↑

资源预览