Eric Yih's Blog
posts - 6, comments - 0, trackbacks - 0, articles - 0
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
练习程序
Posted on 2008-03-05 21:58
Eric Yih
阅读(20)
评论(0)
编辑
收藏
1
#
Fig. 3.10: fig03_10.py
2
#
Class average program with counter-controlled repetition
3
4
#
Initialization phase
5
total
=
0
#
sum of grades
6
counter
=
0
#
number of grades entered
7
8
#
processing phase
9
while
counter
<
10
:
#
loop 10 times
10
grade
=
raw_input(
"
Please enter grade of student:
"
)
#
get one grade
11
grade
=
int(grade)
#
convert string to an integer
12
total
=
total
+
grade
13
counter
=
counter
+
1
14
15
print
"
total:
"
, total
16
print
"
counter:
"
, counter
17
18
#
termination phase
19
average
=
total
/
counter
#
integer division
20
print
"
Class average is:
"
, average
1
#
Fig. 3.11: fig03_11.py
2
#
Class average program with sentinel-controlled repetition
3
4
#
Initialization phase
5
total
=
0
#
sum of grades
6
counter
=
0
#
number of grades entered
7
8
grade
=
raw_input(
"
Please enter grade of student:
"
)
9
if
grade
==
""
or
grade
==
"
end
"
:
10
print
"
no grades were entered!
"
11
else
:
12
grade
=
int(grade)
13
total
=
total
+
grade
14
counter
=
counter
+
1
15
while
grade
<>
"
end
"
:
16
grade
=
raw_input(
"
Please enter grade of student:
"
)
17
if
grade
<>
"
end
"
:
18
grade
=
int(grade)
19
total
=
total
+
grade
20
counter
=
counter
+
1
21
22
print
"
total:
"
, total
23
print
"
counter:
"
, counter
24
average
=
total
/
counter
25
print
"
Class average is:
"
, average
Tag标签:
python
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
经典推荐--.NET几大热点问题(.NET人员必读)
博客园程序源代码下载
C#下如何实现服务器+客户端的聊天程序
Python 2.6 正式版发布
Python发布2.6a3和3.0a5版本
相关链接:
最新IT新闻:
金融风暴改写富豪榜排名 巴菲特资产超盖茨
红杉资本发出严重警告:黄金时代已成历史
2008年10月11日科技博客精选
搞死开心网还是搞活他?
网络书店“新”军
Powered by:
博客园
Copyright © Eric Yih
日历
<
2008年3月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
与我互动
给我发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
我的标签
留言簿
给我留言
查看私人留言
我的标签
ASCII码(1)
python(1)
随笔档案
2008年5月 (2)
2008年3月 (2)
2008年1月 (2)
技术博客
ScottGu's Blog
TerryLee's Tech Space
技术网站
CodePlex
Dive Into Python
Python Official Website
The Official Microsoft ASP.NET Site
最新评论
阅读排行榜
1. Python简介[转](852)
2. .Net Framework Library Source Code now available(131)
3. Installing DB2 UDB Version 8.2(30)
4. 练习程序(20)
5. The Perfect Setup - Debian Etch (Debian 4.0) (一)(13)
评论排行榜
1. .Net Framework Library Source Code now available(0)
2. Python简介[转](0)
3. 常用ASCII码对照表(备忘)(0)
4. 练习程序(0)
5. Installing DB2 UDB Version 8.2(0)