發表文章

怪怪的程式語言名稱:Brainfuck

最近在 ptt Gossiping 版的jserv 的一篇回文 https://www.ptt.cc/bbs/Gossiping/M.1555612071.A.14C.html 得知 Brainfuck 也是個程式語言,於是小編自己也來寫一個 Brainfuck interpreter。先來了解 Brainfuck 的指令吧。 Brainfuck指令說明 ============底下文字從  https://en.wikipedia.org/wiki/Brainfuck  節錄出來:============ Character Meaning > increment the  data pointer  (to point to the next cell to the right). < decrement the data pointer (to point to the next cell to the left). + increment (increase by one) the byte at the data pointer. - decrement (decrease by one) the byte at the data pointer. . output the byte at the data pointer. , accept one byte of input, storing its value in the byte at the data pointer. [ if the byte at the data pointer is zero, then instead of moving the  instruction pointer  forward to the next command,  jump  it  forward  to the command after the  matching   ]  command. ] if the byte at the data pointer is nonzero, then instead of movin...

簡易 Python 問答機器人(Simple Python QA Robot)

圖片
本篇文章會以一個 簡易問答機器人 來了解底下的 Python 相關知識:變數、字串、函數、字典、if/if else/if elif else 判斷式、for 迴圈。 聊天機器人程式架構 儲存問題與答案的 quiz 串列。 兩個主要函數:sendMsg 函數、readMsg 函數。 變數(Variables) 底下用非很精準的解釋,畢竟變數和容器還是不一樣的觀念 變數可看成容器,而容器有很多種,例如罐子、紙箱、寶特瓶、水桶、背包、鉛筆盒等。 但若是有30個人都帶著一模一樣的罐子容器時,那要怎麼辨別這個罐子是誰的啊?! 所以就給這些罐子一個獨一無二的名稱!開始來命名囉! 「豬頭 罐子 」、「空 罐子 」、「軟 罐子 」、「硬 罐子 」、「無敵 罐子 」、「我的 罐子 」、「你的 罐子 」、「不說話 罐子 」、「機器人 罐子 」、「腳 罐子 」、「黑 罐子 」、「紅 罐子 」 可以亂命名嗎?!好像不給個規則會產生一些怪怪的名稱。在程式語言裡,變數是有命名規則的,大多的程式語言通常會有底下兩個規則: 第一個字 必須是英文字母(大小寫字母皆可)或是底線字元「_」 , 不可以是數字或其他符號 。 第一個字 之後的其他字必須是英文字母(大小寫字母皆可)、底線字元「_」或是數字 , 不可以使用其他符號 。 而 Python 提供的容器( Data Types )有底下幾種: 文字容器(Text Type):字串(string)。 數字容器(Numeric Types):整數(int)、浮點數(float)、複數(complex)。 序列容器(Sequence Types):串列(list)、元組(tuple)、range( 小編不知道要如何翻成中文 )。 映射容器(Mapping Type):字典(dict)。 集合容器(Set Types):可變集合(set)、不可變集合(frozenset)。 布林容器(Boolean Type):布林(bool)。 二元容器(Binary Types):位元組(bytes)、位元組陣列(bytearray)、memoryview( 小編不知道要如何翻成中文 )。。 Python 變數的使用方式如下: 1 2 3 4 5 6 7 8 9 10 ...