In [ ]:
#练习一:自己定义一个reverse(s)函数,功能返回字符串s的倒序字符串。
def reverse():
    s = tuple(input("please enter a string,end with a tab: "))
    print(s[::-1])
    
reverse()

In [5]:
#练习三:和发音规则无关的特例咋整啊...呜呜呜呜呜呜呜
#s[i] = x [1,2,1,4,5,6,7,8] s中第i个对象替换成x
#s.append(x) [1,2,3,4,5,6,7,8,1] 将x加入到s的末端,等价于s[len(s):len(s)] = [x]

def plural():
    word = [input('please enter a noun,end with a tab: ')]
    i = 0

    if word[len(word)-1] == 'o' or word[len(word)-1] == 's' or word[len(word)-1] == 'x' or word[len(word)-1] == 'sh' or word[len(word)-1] == 'ch':
        word.append('e')
        word.append('s')
    elif word[len(word)-1] == 'y':
        if word[len(word)-2] != 'a' or word[len(word)-2] != 'e' or word[len(word)-2] != 'i' or word[len(word)-2] != 'o' or word[len(word)-2] != 'u':
            word[len(word)-1] = 'i'
            word.append('e')
            word.append('s')
        else :
            word.append('s')
    else :
        word.append('s')
        
    for i in range(len(word)):
        print(word[i],end='')
    
    

plural()


please enter a noun,end with a tab: apple
apples

In [17]:
#练习二:写函数,根据给定符号和行数,打印相应直角三角形,等腰三角形及其他形式的三角形。
def right_tri():
    l = int(input('please enter a row,end with a tab: '))
    s = 't'*l
    
    for i in range(1,len(s)+1):
        for j in range(0,i):
            print(s[0],end='')
        print()
def iso_tri():
    l = int(input('please enter an odd integer,end with a tab: '))
    s = 't'*l
    t = l
    
    for i in range(1,l+1):
        print(' '*t,s[0]*(2*i-1))
        t -=1
     
right_tri()
iso_tri()


please enter a row,end with a tab: 5
t
tt
ttt
tttt
ttttt
please enter an odd integer,end with a tab: 5
      t
     ttt
    ttttt
   ttttttt
  ttttttttt