In [1]:
#exercise 1
def reverse (s):
    print(s[len(s)-1::-1])
s=str(input("plz enter a string"))
reverse(s)


plz enter a stringi love u
u evol i

In [2]:
#exercise 2
def triangle (x):
    for i in range (x): 
        if i<x-1:
            print('|'+' '*i+'\\')
        elif i==x-1:  print('|'+'_'*i+'\\')
    print(' ')
    for i in range (x):
        if i<x-1:
            print(' '*(x-i)+'/'+' '*(2*i)+'\\')
        elif i==x-1:
            print(' '+'/'+'_'*(i+x-1)+'\\')
    
x=int(input("plz enter the height of the triangle\n"))
triangle(x)


plz enter the height of the triangle
2
|\
|_\
 
  /\
 /__\

In [3]:
#exercise 3
def change(word):
    print('The plurality of the noun is  ',end='')
    if word.endswith('ch') or word.endswith('sh'):
        print(word+'es')
    elif word.endswith('x') or word.endswith('s') or word.endswith('es'):
        print(word+'es')
    elif word.endswith('f'):
        print(word[:len(word)-1:]+'ves')
    elif word.endswith('y'):
        print(word[:len(word)-1:]+'ies')
    else: print(word+'s')
        
word=str(input("plz enter a countable noun\n"))
change(word)


plz enter a countable noun
eye
The plurality of the noun is  eyes

In [10]:
#exercise 4
def tixing(a,b,c,d):
    if b<=c:
        k=(c-b)//(d-1)
        for i in range(d):
            print(b*a+k*a*i)
    else:
        k=k=(b-c)//(d-1)
        for i in range(d):
            print((b-k*i)*a)
x=input('请输入给定符号')
A=int(input('请输入上底长度'))
B=int(input('请输入下底长度'))
h=int(input('请输入高度'))
tixing(x,A,B,h)


请输入给定符号-
请输入上底长度5
请输入下底长度3
请输入高度2
-----
---

In [5]:
#exercise 5
def rhombus (x):
    for i in range (x):
            print(' '*(x-i)+'/'+' '*(2*i)+'\\')
    for i in range(x-1,-1,-1):
        print(' '*(x-i)+'\\'+' '*(2*(i))+'/')
x=int(input('请输入菱形的边长  '))
rhombus(x)


请输入菱形的边长  4
    /\
   /  \
  /    \
 /      \
 \      /
  \    /
   \  /
    \/

In [6]:
#exercise 6
def inverted(x):
    for i in range(len(x)*2,0,-1):
        if i == 1:
            print(' '*(len(x)*2-1) +x[0])
        elif i%2 == 1:
            print(' '*(len(x)*2-i) + x[:i//2] + x[i//2] + x[i//2-1::-1])
        else:
            print(' '*(len(x)*2-i) + x[:i//2] + x[i//2-1::-1])

def main():
    word = '赏花归去马如飞'
    inverted (word)
    

if __name__ == '__main__':
    main()


赏花归去马如飞飞如马去归花赏
 赏花归去马如飞如马去归花赏
  赏花归去马如如马去归花赏
   赏花归去马如马去归花赏
    赏花归去马马去归花赏
     赏花归去马去归花赏
      赏花归去去归花赏
       赏花归去归花赏
        赏花归归花赏
         赏花归花赏
          赏花花赏
           赏花赏
            赏赏
             赏

In [ ]: