1. 程式人生 > >【筆記】嵩天-Python語言程序設計-完成兩個簡單實例

【筆記】嵩天-Python語言程序設計-完成兩個簡單實例

字母 輸入 port temp 過程 family 設計 log 目錄

【根索引】 【Python索引】

目標

使用PyCharm,完成兩個小實例的編寫和運行。一個是溫度轉換,一個是蟒蛇圖形繪制。

過程

1、先設置project目錄,雖然命名不是很正式,主要不太習慣軟件的目錄結構,好在只是熟悉語言和工具,就先把代碼都放一個目錄下吧。

2、可以打開多個py文件,運行時可以分別運行,如下圖B部分。記得選擇編譯器。

3、運行結果見C。

總的來說,這些實例都很簡單,主要還是動手體驗下,對編輯環境的熟悉。

技術分享圖片

代碼

溫度轉換代碼:

# Temperature conver, between C and F.

TempStr = input("請輸入溫度,數字+字母F或C結尾:
") if TempStr[-1] in ["F", "f"]: temp = (eval(TempStr[0:-1]) - 32) / 1.8 print("攝氏溫度為:{:.2f}C".format(temp)) elif TempStr[-1] in ["C", "c"]: temp = eval(TempStr[0:-1]) * 1.8 + 32 print("華氏溫度為:{:.2f}F".format(temp)) else: print("輸入格式錯誤")

蟒蛇繪制代碼:

#PythonDraw.py
import
turtle #turtle.setup(1290, 730, 0, 0) turtle.setup(700, 700) turtle.penup() turtle.fd(-250) turtle.pendown() turtle.pensize(25) turtle.pencolor("pink") #brown, purple turtle.seth(-40) for i in range(3): turtle.circle(40, 80) turtle.circle(-40, 80) turtle.circle(40, 80/2) turtle.fd(40) turtle.circle(
16, 180) turtle.fd(40 * 2/3) turtle.done()

=======================

by NicoWei
2018-12-5 00:18:08

=======================

【筆記】嵩天-Python語言程序設計-完成兩個簡單實例