原创 笨辦法學Python3 習題39和習題40

習題38 列表的操作 # create a mapping of state to an abbreviation states = { 'Oregon': 'OR', 'Florida': 'FL', 'Cal

原创 笨辦法學Python3 習題29和習題30

習題29 people = 20 cats = 20 dogs = 15 if people < cats: print("Too many cats! The world is doomed!") if people >

原创 笨辦法學Python3 習題24和習題25

基於Python3.6 習題24 print("Let's practice everything.") print('You\'d need to know \' bout escapes withe \\ that do \n ne

原创 笨辦法學Python3 習題47-48

習題47 自動化測試 被測試文件 class Room(object): def __init__(self, name, description): self.name = name self

原创 笨辦法學Python3 習題21和習題22

基於Pyhton3.6 習題21 def add(a, b): print("ADDING %d + %d" % (a, b)) return a + b def subtract(a, b): print("

原创 笨辦法學Python3 習題31

習題31 print("You enter a dark room with two doors. Do you go through door #1 or door #2?") door = input("> ") if door

原创 笨辦法學Python3 習題35

習題35 分支和函數 from sys import exit def gold_room(): print("This room is full of gold. How much do you take?")

原创 笨辦法學Python3 習題40和習題41

習題40 模塊、類、對象 class Song(object): def __init__(self,lyrics): self.lyrics = lyrics def sing_me_a_song(s

原创 笨辦法學Python3 習題18和19

 基於Python3.6 習題18 def print_two(*args): arg1, arg2 = args print("arg1: %r, arg2: %r" %(arg1, arg2)) def prin

原创 笨辦法學Python3 習題32和習題33

習題32 循環和列表 the_count = [1, 2, 3, 3, 5] fruits = ['apples', 'oranges', 'pears', 'apricots'] change = [1, 'pennies', 2,

原创 笨辦法學Python3 習題20

基於Python3.6 習題20 from sys import argv #從命令行輸入要讀取的文件 script, input_file = argv #定義輸入全部文件內容的函數 def print_all(f): pri

原创 笨辦法學Python3 習題16

基於Python3.6 習題16 from sys import argv script, filename = argv print("We're going to erase %r." % filename) print("If

原创 笨辦法學Python3 習題43

習題43 來自Percal 25號行星的哥頓人 import random from urllib.request import urlopen import sys WORD_URL = "http://learncodetheha

原创 Octacve矩陣運算(一)

Octave中的矩陣加法矩陣的加法是最簡單的,但是我將從元素和矩陣兩個角度來分析這個問題,通過舉例來實際說明>> A=[1,2,3;4,5,6;7,8,9;] A = 1 2 3 4 5 6 7 8

原创 Octave矩陣運算(三)

矩陣的一些更復雜的運算首先是矩陣的平方和矩陣元素的平方>> A=[1,2,3;4,5,6;7,8,9] A = 1 2 3 4 5 6 7 8 9 >> A^2 ans = 30