if cls == 'human' and sex == 'female' and age > 16 and age < 22:
記成了:
if name == 'cyd' or 'chenyoude' or 'yd' or '有德' or '陳有德':
總是輸出有問題,搞得自己把它弄成列表+for 循環:
self_names = ['cyd', 'chenyoude', 'yd', '陳有德', '有德']
for self_name in self_names:
if name == self_name:
但是又有個最後又增添'continue',實在是累死人,最後兩處地方有一處因爲在while循環內部,可以修改,而另一處也就是我的名字那裏不能修改,所以我這個小遊戲的bug就是如果輸入我name_self列表中第二個以後的元素,都會把我自己的名字運行進遊戲,而達不到我想要的輸入我名字就顯示'你可以試試cyd,休想用我的名子來運行這款遊戲...’這個效果,很是失敗,和上次專升本一樣,一個小小的東西因爲記錯了卻浪費了大部分時間。哎!!!下面實我的小遊戲的源碼,還有很多地方做不到心裏所想的,不準備修改,以此激勵自己還有很多不足的:def spoof_game(惡搞1, 惡搞2, 惡搞3):
count = 0
self_names = ['cyd', 'chenyoude', 'yd', '陳有德', '有德']
nums = ['1', '2', '3', '4', '5', '6']
tag = True
name = input("很好玩的一個遊戲,請輸入您的姓名:\n")
while tag:
for self_name in self_names:
if name == self_name:
print('你可以試試cyd,休想用%s來運行這款遊戲!有個Bug留給你惡搞我,嘻嘻!' %name)
tag = False
elif name != self_name:
while tag:
print('歡迎觀臨,'+惡搞1+'%s!' % name)
word = input("""您可以輸入'q'退出遊戲(退出是%s哦!)...
瞎按需要重新輸入,按'q'你就知道爲什麼了,哈哈哈!!!
請隨便輸入1-6中任何一個數字:\n""" %惡搞2)
if word == 'q':
print('慫蛋,遊戲開始了,你還想跑???\n')
if word != 'q':
for num in nums:
if word != num:
continue
elif word == num:
while count < 3:
count += 1
print('%s是我,我是' %name + 惡搞3 + '!OhYeah!')
if count == 3:
print('''重要的話重複三遍
你是不是天真的以爲數字%s以外的選擇會是其他的獎勵呢?哈哈哈!!!''' %word)
tag = False
print(spoof_game('巨醜怪', '慫蛋', '巨大傻瓜'))
流程控制之if判斷:
語法1:
if 條件:
代碼塊1
語法2:
if 條件:
代碼塊1
else:
代碼塊2
語法3:
if 條件:
代碼塊1
elif 條件:
代碼塊2
...(多個elif 條件:)
else:
代碼塊3
if的嵌套:
if 條件:
代碼塊1
if 條件:
代碼塊2
else:
代碼塊3
else:
代碼塊4
流程控制之while循環——條件循環
while 條件:
代碼塊1
while + break 表示終止當前的循環:
while 條件:
代碼塊1
if 條件:
代碼塊2
break
else:
代碼塊3
while + continue 表示終止掉本次循環,直接進入下一循環
注意:continue一定不要加到循環體的最後一步執行的代碼
while 條件:
代碼塊1
if 條件:
代碼塊2
continue
代碼塊3
else:
代碼塊4
while循環嵌套
while 條件1:
代碼塊1
if 條件:
代碼塊2
while 條件:
代碼塊3
if 條件:
代碼塊4
else:
代碼塊5
break
else:
代碼塊6
while + tag
tag = True
while tag:
代碼塊1
if 條件:
代碼塊2
while 條件:
代碼塊3
if 條件:
tag = False
else:
代碼塊4
else:
代碼塊5
while + else
在整個循環結束後,會進行判斷:只有while循環在沒有被break結束掉的情況下才會執行else中的代碼
while 條件:
代碼塊1
else:
代碼塊2
流程控制之for循環:
1.取出列表中的值
for循環嵌套:
for 條件1:
for 條件2:
先進行條件1的第一個循環,然後把條件2的所有循環掉,然後進行條件1的第二個循環,然後也會把條件2全部循環一次
for+break
在一個特定值處終止循環
for+continue
跳過一個特定的值,進行下一個數據的搜索
for+else
在整個循環結束後,會進行判斷:只有for循環在沒有被break結束掉的情況下才會執行else中的代碼