编写一个函数,有三个形式参数,其中两个传递字符分别作为开始字符和结束字符,打印出两个字符之间的所有字符,每行打印的字符个数由第三个形式参数指定。利用该函数打印出“!”和“9”之间的所有字符,每行打印10个。
#!/usr/bin/python
# -*- coding: utf-8 -*-
def func(start, end, n):
c = 0
for i in range(ord(start), ord(end) + 1):
print(chr(i), end='')
c += 1
if c % n == 0:
print()
else:
print(' ', end='')
func('!', '9', 10)
意思就是根据开始和结束字符串, 判断ascii , 输出之间所有字符。
按第三个参数 控制每行输出多少
def func(sf,sd,sep):
s=''
for i in range(ord(sf)+1,ord(sd)):
s += chr(i)
if len(s)==sep:
print(s)
s=''
print(s)#不够十个的
func("!","9",10)