day01基礎知識
day02知識分類
day03運算子
day04數字與字串
day05列表
day06元組與字典
day07條件與迴圈
day08函式概念
day09資料結構
day10模組介紹
day11檔案操作
day12程式設計學習
day13程式設計學習
day14程式設計學習
day15程式設計學習
day16程式設計學習
day17程式設計學習
day18程式設計學習
python hello world 例項
# -*- coding: utf-8 -*-
# filename : helloworld.py
# 該例項輸出 hello world!
print
('hello world!'
)
python數字求和# -*- coding: utf-8 -*-
# 使用者輸入數字
num1 =
input
('輸入第乙個數字:'
)num2 =
input
('輸入第二個數字:'
)# 求和
sum=
float
(num1)
+float
(num2)
# 顯示計算結果
print
('數字 和 相加結果為: '
.format
(num1, num2,
sum)
)
# -*- coding: utf-8 -*-
# filename : test.py
print
('兩數之和為 %.1f'%(
float
(input
('輸入第乙個數字:'))
+float
(input
('輸入第二個數字:'))
))
python平方根# -*- coding: utf-8 -*-
# filename : test.py
num =
float
(input
('請輸入乙個數字: '))
num_sqrt = num **
0.5print
(' %0.3f 的平方根為 %0.3f'
%(num ,num_sqrt)
)
# -*- coding: utf-8 -*-
# filename : test.py
# 計算實數和複數平方根
# 匯入複數數學模組
import cmath
num =
int(
input
("請輸入乙個數字: "))
num_sqrt = cmath.sqrt(num)
print
(' 的平方根為 +j'
.format
(num ,num_sqrt.real,num_sqrt.imag)
)
python二次方程# filename : test.py
# 二次方程式 ax**2 + bx + c = 0
# a、b、c 使用者提供,為實數,a ≠ 0
# 匯入 cmath(複雜數**算) 模組
import cmath
a =float
(input
('輸入 a: '))
b =float
(input
('輸入 b: '))
c =float
(input
('輸入 c: '))
# 計算
d =(b**2)
-(4*a*c)
# 兩種求解方式
sol1 =
(-b-cmath.sqrt(d))/
(2*a)sol2 =
(-b+cmath.sqrt(d))/
(2*a)print
('結果為 和 '
.format
(sol1,sol2)
)
python計算三角形面積# -*- coding: utf-8 -*-
# filename : test.py
a =float
(input
('輸入三角形第一邊長: '))
b =float
(input
('輸入三角形第二邊長: '))
c =float
(input
('輸入三角形第三邊長: '))
# 計算半周長
s =(a + b + c)/2
# 計算面積
area =
(s*(s-a)
*(s-b)
*(s-c))**
0.5print
('三角形面積為 %0.2f'
%area)
計算圓的面積# 定義乙個方法來計算圓的面積
deffindarea
(r):
pi =
3.142
return pi *
(r*r)
# 呼叫方法
print
("圓的面積為 %.6f"
% findarea(5)
)
end
這幾天有點忙,所以內容就比較少了,前面的知識點都過的差不多了,後續就是找一堆例子乙個乙個復現**,然後再學習python的其他高階知識,希望明天能檢查下來吧,加油。
day13 函式入門
目錄2.呼叫函式 3.函式的返回值 函式就相當於具備某一功能的工具 函式的使用要遵循乙個原則 先定義 後呼叫 冗餘,程式的組織結構不清晰,可讀性差 可維護性擴充套件性差 函式定義的語法 def 函式名 引數1,引數2 文件描述 函式體return 值函式分為定義和呼叫兩個階段 定義函式 只檢測語法,...
python之路 day13 模組
1,什麼是模組 模組就是系統功能的集合體,在python中,乙個py檔案就是乙個模組,例如 module.py 其中module叫做模組名 2,使用模組 2.1 import匯入模組 首次帶入模組發生三件事 1,建立乙個模組的命名空間 2,執行模組對應檔案,將產生的名字存放於1中的命名空間 3,在當...
python入門day13 命名空間作用域
作用域 作用範圍 命名空間就是存放名字的地方,是對棧區的劃分 有了命名空間之後,就可以在棧區中存放相同的名字,詳細的命名空間,分為三種 內建命名空間 全域性命名空間 區域性命名空間 內建命名空間存放的是python直譯器內建的名字,如print input len 存活週期 python直譯器啟動則...