2019年6月30日日曜日

開発環境

Head First はじめてのプログラミング ―頭とからだで覚えるPythonプログラミング入門 (Eric Freeman(著)、嶋田 健志(監修)、木下 哲也(翻訳)、株式会社オライリー・ジャパン)を6章(テキスト、文字列、ヒューリスティック - すべてを組み合わせる)の自分で考えてみよう(255ページ)の解答を求めてみる。

コード

Python 3

#!/usr/bin/env python3
import ch1text


def compute_readability(text):
    total_words = 0
    total_sentences = 0
    total_syllables = 0
    score = 0
    words = text.split()
    total_words = len(words)

    print(words)
    print(total_words, 'words')


compute_readability(ch1text.text)

入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

C:\Users\...>py sample1.py
['The', 'first', 'thing', 'that', 'stands', 'between', 'you', 'and', 'writing', 'your', 'first,', 'real,', 'piece', 'of', 'code,', 'is', 'learning', 'the', 'skill', 'of', 'breaking', 'problems', 'down', 'into', 'acheivable', 'little', 'actions', 'that', 'a', 'computer', 'can', 'do', 'for', 'you.', 'Of', 'course,', 'you', 'and', 'the', 'computer', 'will', 'also', 'need', 'to', 'be', 'speaking', 'a', 'common', 'language,', 'but', "we'll", 'get', 'to', 'that', 'topic', 'in', 'just', 'a', 'bit.', 'Now', 'breaking', 'problems', 'down', 'into', 'a', 'number', 'of', 'steps', 'may', 'sound', 'a', 'new', 'skill,', 'but', 'its', 'actually', 'something', 'you', 'do', 'every', 'day.', 'Let’s', 'look', 'at', 'an', 'example,', 'a', 'simple', 'one:', 'say', 'you', 'wanted', 'to', 'break', 'the', 'activity', 'of', 'fishing', 'down', 'into', 'a', 'simple', 'set', 'of', 'instructions', 'that', 'you', 'could', 'hand', 'to', 'a', 'robot,', 'who', 'would', 'do', 'your', 'fishing', 'for', 'you.', 'Here’s', 'our', 'first', 'attempt', 'to', 'do', 'that,', 'check', 'it', 'out:', 'You', 'can', 'think', 'of', 'these', 'statements', 'as', 'a', 'nice', 'recipe', 'for', 'fishing.', 'Like', 'any', 'recipe,', 'this', 'one', 'provides', 'a', 'set', 'of', 'steps,', 'that', 'when', 'followed', 'in', 'order,', 'will', 'produce', 'some', 'result', 'or', 'outcome', 'in', 'our', 'case,', 'hopefully,', 'catching', 'some', 'fish.', 'Notice', 'that', 'most', 'steps', 'consists', 'of', 'simple', 'instruction,', 'like', '"cast', 'line', 'into', 'pond",', 'or', '"pull', 'in', 'the', 'fish."', 'But', 'also', 'notice', 'that', 'other', 'instructions', 'are', 'a', 'bit', 'different', 'because', 'they', 'depend', 'on', 'a', 'condition,', 'like', '“is', 'the', 'bobber', 'above', 'or', 'below', 'water?".', 'Instructions', 'might', 'also', 'direct', 'the', 'flow', 'of', 'the', 'recipe,', 'like', '"if', 'you', 'haven’t', 'finished', 'fishing,', 'then', 'cycle', 'back', 'to', 'the', 'beginning', 'and', 'put', 'another', 'worm', 'on', 'the', 'hook."', 'Or,', 'how', 'about', 'a', 'condition', 'for', 'stopping,', 'as', 'in', '“if', 'you’re', 'done”', 'then', 'go', 'home.', 'You’re', 'going', 'to', 'find', 'these', 'simple', 'statements', 'or', 'instructions', 'are', 'the', 'first', 'key', 'to', 'coding,', 'in', 'fact', 'every', 'App', 'or', 'software', 'program', 'you’ve', 'ever', 'used', 'has', 'been', 'nothing', 'more', 'than', 'a', '(sometimes', 'large)', 'set', 'of', 'simple', 'instructions', 'to', 'the', 'computer', 'that', 'tell', 'it', 'what', 'to', 'do.']
300 words

C:\Users\...>

0 コメント:

コメントを投稿