今天是看這本書Automate the Boring Stuff with Python(Python編程快速上手--讓繁瑣工作自動化)
第一章節(Python Basics)所做的練習
用Notepad++打下列的程式碼,
另存為Chapter_1.py. 我附上中文注釋方便好讀.
# -*- coding: UTF-8 -*- # http://juilin77.blogspot.com/ # v20181201 # Automate The Boring Stuff With Python - Chapter 1 # 印出初學者第一個最重要的Hello, World! print('Hello, World!') # 印出What is your name? print('What is your name?') # 輸入字符(MyName) MyName = input() # 印出It is good to see you, 後面接上剛剛輸入的姓名 print('It is good to see you, ' + MyName) # 印出The length of your name is: print('The length of your name is: ') # 印出姓名的字元長度 print(len(MyName)) # 印出What is your age? print("What is your age?") # 輸入數字(MyAge) MyAge = input() # 先剛剛剛輸入的MyAge轉為整數型(int), 好方便後面的 + 1. # 然後再轉為字符型(str), 好方便跟前後兩句字符拼接再一起. print('You will be ' + str(int(MyAge) + 1) + ' in this year.')
然後用Windows的cmd, 執行python.
D:\Tech\Python\AutomateTheBoringStuffWithPython>python Chapter_1.py Hello, World! What is your name? Peter It is good to see you, Peter The length of your name is: 5 What is your age? 3 You will be 4 in this year. D:\Tech\Python\AutomateTheBoringStuffWithPython>
完成
Reference:
Automate the Boring Stuff with Python
Python编程快速上手:让繁琐工作自动化
ISBN-10: B01N6B9BSA
https://www.amazon.com/Python%E7%BC%96%E7%A8%8B%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B-%E8%AE%A9%E7%B9%81%E7%90%90%E5%B7%A5%E4%BD%9C%E8%87%AA%E5%8A%A8%E5%8C%96-%E7%BE%8E-Al-Sweigart%EF%BC%88%E6%96%AF%E7%BB%B4%E5%8A%A0%E7%89%B9%EF%BC%89/dp/B01I0XN8XY/ref=sr_1_1?ie=UTF8&qid=1543814481&sr=8-1&keywords=9787115422699
官網:
https://automatetheboringstuff.com/
最初發表 / 最後更新: 2018.12.01 / 2018.12.01
0 comments:
張貼留言