一个疑问
时间:2010-12-11
来源:互联网
本帖最后由 eeeee159963 于 2010-12-11 19:09 编辑
复制代码
第51行的while循环结束条件是什么
- # Credit inquiry program.
-
- import sys
-
- # retrieve one user command
- def getRequest():
-
- while 1:
- request = int( raw_input( "\n? " ) )
-
- if 1 <= request <= 4:
- break
-
- return request
-
- # determine if balance should be displayed, based on type
- def shouldDisplay( accountType, balance ):
-
- if accountType == 2 and balance < 0: # credit balance
- return 1
-
- elif accountType == 3 and balance > 0: # debit balance
- return 1
-
- elif accountType == 1 and balance == 0: # zero balance
- return 1
-
- else: return 0
-
- # print formatted balance data
- def outputLine( account, name, balance ):
-
- print account.ljust( 10 ),
- print name.ljust( 10 ),
- print balance.rjust( 10 )
-
- # open file
- try:
- file = open( "clients.dat", "r" )
- except IOError:
- print >> sys.stderr, "File could not be opened"
- sys.exit( 1 )
-
- print "Enter request"
- print "1 - List accounts with zero balances"
- print "2 - List accounts with credit balances"
- print "3 - List accounts with debit balances"
- print "4 - End of run"
-
- # process user request(s)
- while 1:
-
- request = getRequest() # get user request
-
- if request == 1: # zero balances
- print "\nAccounts with zero balances:"
- elif request == 2: # credit balances
- print "\nAccounts with credit balances:"
- elif request == 3: # debit balances
- print "\nAccounts with debit balances:"
- elif request == 4: # exit loop
- break
- else: # getRequest should never let program reach here
- print "\nInvalid request."
-
- currentRecord = file.readline() # get first record
-
- # process each line
- while ( currentRecord != "" ):
- account, name, balance = currentRecord.split()
- balance = float( balance )
-
- if shouldDisplay( request, balance ):
- outputLine( account, name, str( balance ) )
-
- currentRecord = file.readline() # get next record
-
- file.seek( 0, 0 ) # move to beginning of file
-
- print "\nEnd of run."
- file.close() # close file
-
第51行的while循环结束条件是什么
作者: eeeee159963 发布时间: 2010-12-11
elif request == 4: # exit loop
break
break
作者: catcat811 发布时间: 2010-12-11
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28