記錄預留處:討論完成後,負責記錄的人將在此更新。
預計討論時間:1月31日(週日)下午2點
新手可以簡單說一下,這章你們看到什麼嗎?
(不好意思,新手還在上這天的課,現在先旁聽大家討論)
這章的主題,就在標題中:亂數 和 陣列(不曉得用這個是否正確,我沒看中文)
import random
random.randint(a,b)
try: # 看到先記一下
xxx
except ValueError:
yyy
random.random() # value in the interval[0,1) # not include 1
首先引進了宣告的概念。
之前的 print(), input() 都可以直接用,是因為太常用,程式預設就幫你放進程式庫。
一時沒想到合適的例子。就像楚留香去偷東西前,會先通知主人,我什麼時候會來拿走這個喔。沒通知,就不會來偷。
要先宣告,然後程式中,才可以使用相關的 function
random 的語法,請參考 Cheat sheet 速查表。
random.randint(a,b)
random.random()
…
這個則是除錯用,現在還用不到。
然後看日期,發現這個課程,從2019年就開始設計了。
■ 4-41. Understanding the Offset and Appending Items to Lists
■ ■ List
Data Structures — Python 3.9.1 documentation
https://docs.python.org/3/tutorial/datastructures.html
CheatSheet-Python-3_-Complex-Data-Types.pdf
■ List = [item1, item2]
List[-1]
List.append(item_n)
List.extend(item_m, item_n) # 兩個 cheat sheet 都沒提到
■ 不用記,要用的時候再查就好
open book examination
4-42. #Exercise
■ split
names_string = input("Give me everybody’s names, separated by a comma. “)
names = names_string.split(”, ")
4-43. IndexErrors and Working with Nested Lists
■ ■ Nested Lists
list1 = [item1, item2]
lista = [itema, itemb]
lists = [list1, lista]
lists[0][0]
4-45. Day 4 Project: Rock Paper Scissors
猜拳 challenge
防呆
if user_choice >= 3 or user_choice < 0:
print(“You typed an invalid number, you lose!”)
玉米有沒有補充?
關於import可以參考一下這個網址
新手們知道「防呆」的意思嗎?
不知道耶
我覺得import應用可以想像成
當你在做點心(寫程式)你需要用到某些材料(程式所需的的工具應用)你要先到超市購買材料(安裝程式套件<pip install>)然後把需要用到的材料放在備料區好隨時取用(import工具)
可能沒有比喻的很好大家參考看看就好
比我的好得多。
防呆的目的在預防使用者,不在預期內的回應。
比方說,猜拳原本希望使用者輸入0, 1, 2,但萬一使用者皮皮蛋,輸入3,甚至是英文字呢?
想多一點,就可以避免這類奇怪回應,所導致的錯誤。
是不是就像Angela常會在問Yes/No的問題後面,加上「Yes or No」,引導回答的人從中選一個回答這樣?