lesson 34
访问列表的元素
索引定义
关于序数(ordinal number)和基数(cardinal number)的知识
例如:
基数:一、二、三、四、五、六、七、八、九、十。
序数:第一、第二、第三、第四、第五、第六、第七、第八、第九、第十。
基数:
在数学上,基数(cardinal number)是集合论中刻画任意集合大小的一个概念。两个能够建立元素间一一对应的集合称为互相对等集合。例如3个人的集合和3匹马的集合可以建立一一对应,是两个对等的集合。
序数:
集合论基本概念之一,是日常使用的第一、第二等表示次序的数的推广。序数概念是建立在良序集概念之上的,而良序集又是偏序集、全序集的特殊情形。
lesson 35 分支和函数
from sys import exit
def goldRoom():
# 房间内充满金子,你愿意出多少钱?
print("This room is full of gold.How much do you take?")
# 请输入金额
next = input("please enter number> ")
# 这里只是判断输入的数字中是否包含0和1
if "0" in next or "1" in next:
howMuch = int(next)
else:
# 同志,请输入数字
dead("Man,learn to type a number.")
if howMuch < 50:
# 很好,你不是很贪婪,你赢了
print("Nice,you're not greedy,you win!")
exit(0)
else:
# 你太过贪婪了
dead("You greedy bastard!")
def bearRoom():
# 房间内有只熊
print("There is a bear here.")
# 熊正在吃蜂蜜
print("The bear has a bunch of honey.")
# 熊正在另一扇门前
print("The fat bear is in front of another door.")
# 我们怎样躲开这只熊
print("How are you going to move the bear?")
bearMoved = False
while True:
next = input("please enter take honey or taunt bear or taunt bear or open door> ")
if next == "take honey":
# 熊看着你,然后拍打你的脸
dead("The bear looks at you then slaps your face off.")
elif next == "taunt bear" and not bearMoved:
# 熊已经从门口走了,你现在可以过去了。
print("The bear has moved from the door.You can go through it now.")
bearMoved = True
elif next == "taunt bear" and bearMoved:
# 熊会生气,咬你的木头
dead("The bear gets pissed off and chews your log off.")
elif next == "open door" and bearMoved:
goldRoom()
else:
# 我不知道是什么意思。
print("I got no idea what means.")
def cthulhuRoom():
print("Here you see the great evil Cthulhu.")
print("He,it,whatever stares at you and you go insane.")
print("Do you flee for your life or eat your head?")
next = input("please enter flee or head> ")
if "flee" in next:
start()
elif "head" in next:
dead("Well that was tasty!")
else:
cthulhuRoom()
# 输出原因并中断运行
def dead(why):
print(why, "Good job!")
exit(0)
def start():
print("You are in a dark room.")
print("There is a door to your right and left.")
print("Which one do you take?")
next = input("please enter left or right:> ")
if next == "left":
bearRoom()
elif next == "right":
cthulhuRoom()
else:
dead("You stumble around the room until you starve.")
start()