python编程练习题和答案(共3页).doc
精选优质文档-倾情为你奉上1. 写程序,输出以下内容for m in range (1,5): for n in range(1,5): print m," ",n print " "写程序,输出以下内容N=5for m in range(1,5): for n in range(1,m+1): print m,"",n print " " 2. 写程序,输出以下内容讨巧的办法就是把第1-2中的m和n互换N=5for m in range(1,N): for n in range(1,m+1): print n,"",m print " "3. 写程序,输出以下内容# encoding: utf-8 def gen(line_cnt): ''' param: line_cnt 行数 ''' for row in range(1,line_cnt+1): for col in range(1,row+1): print '%d %dt' % (col,row), print '' if _name_ = '_main_': gen(4) 4. 写程序,输出以下内容# -*- coding: cp936 -*-#enconding: utf-8def gen(line_cnt): ''': param:行数 ''' for i in range(1,line_cnt+1): for j in range(1,i+1): m=i*j print '%s*%s=%st' % (i,j,m),#这边的逗号很重要,有了逗号,才能不换行 print'' if _name_ = '_main_': gen(9) 专心-专注-专业