<jupyter_start><jupyter_text>练习一：自己定义一个reverse(s)函数，功能返回字符串s的倒序字符串。<jupyter_code>def reverse(s):
    for i in range(0,len(s)):
        j=len(s)-i-1
        print (s[j])         
    
def main():
    text = '赏花归去马如飞'
    reverse(text) 
main()<jupyter_output>飞
如
马
去
归
花
赏<jupyter_text>练习二：写函数，根据给定符号和行数，打印相应直角三角形，等腰三角形及其他形式的三角形。<jupyter_code>def tri1(m,n):
    for i in range(0, n):
        for j in range(0,n-i):           
            print(' ',end='')
        for k in range(0,2*i-1):
            print (m,end='')
        print()
def tri2(m,n):
    for i in range(1,n+1):
        for j in range(1,i+1):
            print (m, end=' ')
        print()  

        
def main():
    sym='*'
    n=int(input('plz input line num: '))
    tri1(sym,n) 
    print()
    tri2(sym,n)
main()<jupyter_output>plz input line num: 7
       
      *
     ***
    *****
   *******
  *********
 ***********

* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * *<jupyter_text>练习三：将任务4中的英语名词单数变复数的函数，尽可能的考虑多种情况，重新进行实现。<jupyter_code>def plur(s):
    l=len(s)
    if (s.endswith('o') or s.endswith('ch') or s.endswith('sh') ):        
        print (s[0:l-1],end='')
        print ('es')
    else:
        print (s[0:l],end='')
        print ('s')        
    
def main():
    s='st'
    while(s != 'q'):
        s=str(input('plz input a word: '))
        plur(s)
main()<jupyter_output>plz input a word: tomato
tomates
plz input a word: apple
apples
plz input a word: sandwich
sandwices
plz input a word: q
qs<jupyter_text>练习四：写函数，根据给定符号，上底、下底、高，打印各种梯形。<jupyter_code>def trap(a,b,h):
    x=(b-a)//h
    for i in range(0,h):
        for j in range(0,a):
            print ('*',end='')
        a+=x
        print()
def main():
    a=int(input('plz input upper line: '))
    b=int(input('plz input lower line: '))
    h=int(input('plz input height: '))
    trap(a,b,h)
main()<jupyter_output>plz input upper line: 4
plz input lower line: 8
plz input height: 4
****
*****
******
*******<jupyter_text>练习五：写函数，根据给定符号，打印各种菱形。<jupyter_code>def tri(m,n):
    for i in range(0, n):
        for j in range(0,n-i):           
            print(' ',end='')
        for k in range(0,2*i-1):
            print (m,end='')
        print()
    for i in range(n,0,-1):
        for j in range(0,n-i):           
            print(' ',end='')
        for k in range(0,2*i-1):
            print (m,end='')
        print()
def main():
    sym='*'
    n=int(input('plz input line num: '))
    tri(sym,n) 
    print()

main()<jupyter_output>plz input line num: 5
     
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *<jupyter_text>练习六：与本小节任务基本相同，但要求打印回文字符倒三角形。<jupyter_code>def plalindrome(line):
    for i in range( len(line)*2,1,-1):
        if i == 1:
            print(' '*(len(line)*2-1) +line[0])
        elif i%2 == 1:
            print(' '*(len(line)*2-i) + line[:i//2] + line[i//2] + line[i//2-1::-1])
        else:
            print(' '*(len(line)*2-i) + line[:i//2] + line[i//2-1::-1])

def main():
    text = '赏花归去马如飞'
    plalindrome(text)

main()<jupyter_output>赏花归去马如飞飞如马去归花赏
 赏花归去马如飞如马去归花赏
  赏花归去马如如马去归花赏
   赏花归去马如马去归花赏
    赏花归去马马去归花赏
     赏花归去马去归花赏
      赏花归去去归花赏
       赏花归去归花赏
        赏花归归花赏
         赏花归花赏
          赏花花赏
           赏花赏
            赏赏
{'fraction_non_alphanumeric': 0.1984004921562596, 'fraction_numerical': 0.01753306674869271, 'mean_word_length': 2.1511627906976742, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '539596', 'license': 'MIT', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1697, 'n_words': 258, 'path': 'chapter2/homework/computer/4-19/201411680496_task7.ipynb', 'repo_name': 'hpishacker/python_tutorial', 'size': '3251'}