练习一:实现reverse(s)函数,功能与s.reverse()相同


In [36]:
def reverse(s):
    temp=s[0]
    s[::]=s[len(s)-1:0:-1]
    s.append(temp)
    return s


words=[1,2,3,4,5,6,7]
print(reverse(words))


[7, 6, 5, 4, 3, 2, 1]

练习二:写函数,根据给定符号和行数,打印相应直角三角形,等腰三角形及其他形式的三角形。


In [22]:
def print_triangle(p,q):
    knot='*'*q
    blank=' '*q
    if p=="直角":
        for i in range(q):
            print(knot[0:i])
    elif p=="等腰":
        for i in range(q,0,-1):
            print(blank[0:i//2]+knot[0:q-i])
    else :
        for i in range(q):
            print('其他形式的三角形')
            
figure=input("please enter the figure: ")
line=int(input("please enter the number of the lines: "))
print_triangle(figure,line+1)


please enter the figure: 等腰
please enter the number of the lines: 6
   
   *
  **
  ***
 ****
 *****

In [ ]:

练习三:将任务4中的英语动词变复数的函数,完整实现。


In [37]:
def converse(s):
    if


  File "<ipython-input-37-3e8a5e064d01>", line 1
    def converse(s):
                    ^
SyntaxError: unexpected EOF while parsing

In [ ]: