2017年2月6日月曜日

開発環境

たのしいプログラミング Pythonではじめよう!(Jason R. Briggs (著)、磯蘭水・藤永奈保子・鈴木悠 (翻訳)、オーム社)の第1部(プログラムの作り方)、第2章(質問なら「if」と「else」におまかせ)、5.8(自分でやってみよう)を取り組んでみる。

コード(Emacs)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 2. カスタードケーキ!
twinkies = 99
if twinkies < 100 or 500 < twinkies:
    print('Too few or too many!')

twinkies = 100    
if twinkies < 100 or 500 < twinkies:
    print('Too few or too many!')

twinkies = 500    
if twinkies < 100 or 500 < twinkies:
    print('Too few or too many!')

twinkies = 501    
if twinkies < 100 or 500 < twinkies:
    print('Too few or too many!')
    
# 3. ちょうどいい数字
money = 99
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 100    
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 500    
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 501    
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 999
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 1000   
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 5000   
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')

money = 5001    
if 100 <= money <= 500:
    print('100-500')
elif 1000 <= money <= 5000:
    print('100-5000')
    

入出力結果(Terminal, IPython)

$ ./sample1.py
Too few or too many!
Too few or too many!
100-500
100-500
100-5000
100-5000
$

0 コメント:

コメントを投稿

Comments on Google+: