Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Python 流程控制
  • Loading branch information
ityouknow committed Aug 18, 2019
1 parent 2c9100e commit dcaaaed
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 1 deletion.
1 change: 0 additions & 1 deletion day-003/Dictionary.py
Expand Up @@ -8,5 +8,4 @@
print (Logo_code['SINA']) # 输出键为 'one' 的值
print (Logo_code.keys()) # 输出所有键
print (Logo_code.values()) # 输出所有值

print (len(Logo_code)) # 输出字段长度
4 changes: 4 additions & 0 deletions day-004/break.py
@@ -0,0 +1,4 @@
for letter in 'ityouknow': # 第一个实例
if letter == 'n': # 字母为 n 时中断
break
print ('当前字母 :', letter)
4 changes: 4 additions & 0 deletions day-004/continue.py
@@ -0,0 +1,4 @@
for letter in 'ityouknow': # 第一个实例
if letter == 'n': # 字母为 n 时跳过输出
continue
print ('当前字母 :', letter)
18 changes: 18 additions & 0 deletions day-004/for.py
@@ -0,0 +1,18 @@
for letter in 'Python': # 第一个实例
print('当前字母 :', letter)

fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # 第二个实例
print('当前水果 :', fruit)

print("Good bye!")



# 通过索引循环

fruits = ['banana', 'apple', 'mango']
for index in range(len(fruits)):
print('当前水果 :', fruits[index])

print("Good bye!")
11 changes: 11 additions & 0 deletions day-004/if.py
@@ -0,0 +1,11 @@
#x = int(input("Please enter an integer: "))
x = -5
if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
print('Zero')
elif x == 1:
print('Single')
else:
print('More')
8 changes: 8 additions & 0 deletions day-004/pass.py
@@ -0,0 +1,8 @@
while True:
pass # Busy-wait for keyboard interrupt (Ctrl+C)


# 这通常用于创建最小结构的类:

class MyEmptyClass:
pass
17 changes: 17 additions & 0 deletions day-004/range.py
@@ -0,0 +1,17 @@
for i in range(6):
print(i)
print(range(6),'finish')

for i in range(6,10):
print(i)
print(range(6,10),'finish')

for i in range(6,12,2):
print(i)
print(range(6,12,2),'finish')


# 迭代链表
a = ['i', 'love', 'coding', 'and', 'free']
for i in range(len(a)):
print(i, a[i])
16 changes: 16 additions & 0 deletions day-004/while.py
@@ -0,0 +1,16 @@
#!/usr/bin/python

count = 0
while (count < 9):
print('The count is:', count)
count = count + 1

print("Good bye!")


count = 0
while count < 6:
print(count, " is less than 6")
count = count + 1
else:
print(count, " is not less than 6")

0 comments on commit dcaaaed

Please sign in to comment.