第三次修改
This commit is contained in:
parent
84a12f998e
commit
d5a0bfdd89
28
2023_0707_code02.py
Normal file
28
2023_0707_code02.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# 学习continue和break
|
||||||
|
|
||||||
|
#假设我要吃5个包子
|
||||||
|
for i in range(1,6):
|
||||||
|
if i == 3:
|
||||||
|
#发现第三个包子,有一只虫
|
||||||
|
continue
|
||||||
|
print(f'吃第{i}个包子')
|
||||||
|
|
||||||
|
#还是吃5个包子
|
||||||
|
for i in range(1,6):
|
||||||
|
if i == 3:
|
||||||
|
#发现第三个包子,有半只虫
|
||||||
|
break
|
||||||
|
print(f'吃第{i}个包子')
|
||||||
|
#给定若干个数字,求平均和
|
||||||
|
theSum = 0 #表示家和的结果
|
||||||
|
count = 0 #表示有几个数字
|
||||||
|
while True:
|
||||||
|
num = input("请输入一个数字:")
|
||||||
|
if num == ';':
|
||||||
|
#约定 用户输入分号,表示输入结束
|
||||||
|
break
|
||||||
|
num = float(num)
|
||||||
|
theSum += num
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
print(f'平均值为:{theSum/count}')
|
Loading…
x
Reference in New Issue
Block a user