Python系統學習第四課

2021-09-06 20:55:51 字數 3649 閱讀 7275

#while 迴圈

· 當乙個條件成立就可以迴圈

· 不知道具體的迴圈次數,但是知道迴圈的成立條件

benjin =

1000

year =

0while benjin <

2000

: benjin = benjin *(1

+0.1

) year +=

1print

("第年拿了塊錢。"

.format

(year,benjin)

)

第1年拿了1100.0塊錢。

第2年拿了1210.0塊錢。

第3年拿了1331.0塊錢。

第4年拿了1464.1000000000001塊錢。

第5年拿了1610.5100000000002塊錢。

第6年拿了1771.5610000000004塊錢。

第7年拿了1948.7171000000005塊錢。

第8年拿了2143.5888100000006塊錢。

#while 的另一種表示式

· while 條件表示式:

語句1else:

語句2·意思是,執行完迴圈之後,再執行一次else語句,只執行一次

#函式· **的一種組織形式

· 乙個**完成一項特定的功能

· 函式需要提前定義

· 使用時,呼叫

def

fun():

print

("i love you ."

)fun(

)#函式呼叫

i love you .
#函式的引數和返回值

· 引數負責給函式傳遞一些必要的資料或者資訊

#函式的定義和使用

defhello

(person)

:print

("hello "

.format

(person)

)l =

"liziqiang"

hello(l)

hello liziqiang
#函式的定義和使用

defhello

(person)

:print

("hello "

.format

(person)

)return

"不理我!"

.format

(person)

#函式返回乙個值

l ="李自強"

rst = hello(l)

print

(rst)

hello 李自強

李自強不理我!

#函式的定義和使用

defhello

(person)

:return

"不理我!!!!"

.format

(person)

#函式返回乙個值

print

("hello "

.format

(person)

)return

"不理我!"

.format

(person)

#函式返回乙個值

l ="李自強"

rst = hello(l)

print

(rst)

李自強不理我!!!!
#99乘法表

defchengfa()

:for i in

range(1

,10):

for j in

range(1

, i+1)

: k = i*j

print

("x="

.format

(i,j,k)

,end =

" ")

print

("\n"

)#換行

chengfa(

)

1x1=1 

2x1=2 2x2=4

3x1=3 3x2=6 3x3=9

4x1=4 4x2=8 4x3=12 4x4=16

5x1=5 5x2=10 5x3=15 5x4=20 5x5=25

6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36

7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49

8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64

9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81

#查詢函式幫助文件

#用help函式

help

(print

)#如果需要列印東西,預設以空格隔開,\n表示換行,

help on built-in function print in module builtins:

print(...)

print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=false)

prints the values to a stream, or to sys.stdout by default.

optional keyword arguments:

file: a file-like object (stream); defaults to the current sys.stdout.

sep: string inserted between values, default a space.

flush: whether to forcibly flush the stream.

#預設引數示例

#報名的人,大多都是男生,如果沒有特別指出,就認為是男生

defbaoming

(name, age, gender =

"male"):

if gender ==

"male"

:print

(" ,he is a good student!"

.format

(name)

)else

:print

(", she is a good student!"

.format

(name)

)

baoming(

"lisi",22

)baoming(

"zhangsan",23

,"female"

)

lisi ,he is a good student!

zhangsan, she is a good student!

鋼琴第四課

因為此前每天都練琴,曲譜也都記住了,所以,週六,臨時被老師喊去時,非常自信。學到了很多知識。1.連貫性方面 連貫性要注意 其實,連貫性在於對曲目的熟練程度,手指的靈活程度,還有不同音之間的連貫跳躍 音要連續 不同音,要連續連線在一起 這個音落下,上個音才起來 2.節奏方面 四分音符要短快,彈到了,立...

Python自學之路 第四課

第4課 測試題 0.請問以下 會列印多少次 我愛魚c!while c print 我愛魚c 答 無限次請寫出與 10 cost 50 等價的表示式 答 10python3 中,一行可以書寫多個語句嗎?答 可以,需要用分號隔開 python3 中,乙個語句可以分成多行書寫嗎?答 可以 用 隔開或者用 ...

C 學習第四課 串

字串 兩種形式,一種是c模式,一種是c 模式 c模式 char a 6 char a hello 幾種函式 strcpy str1,str2 將str2的內容複製到str1上 strcat str1,str2 將str2連到str1的後面 strlen str1 求取字串str1的長度 strcmp...