In [6]:
##练习一:自己定义一个reverse(s)函数,功能返回字符串s的倒序字符串。

def reverse(s): 
    return line[ : : -1]
        
line = input('')
print(reverse(line))


i love kim
mik evol i

In [2]:
#写函数,根据给定符号和行数,打印相应直角三角形,等腰三角形及其他形式的三角形。
def triangle(symbol,rows):
    print ('直角三角形:')   
    for i in range(rows):
        print (' '*(rows-i-1)+symbol*(i+1))
    print ('等腰三角形:')  
    for i in range(rows):
        print (' '*(rows-i-1)+symbol*(i)+'*'+symbol*(i)+' '*(rows-i-1))
    print ('其他三角形:')      
    for i in range(rows):
        if i < rows//2:
            print (' '*(rows-i-1)+symbol*(i+1))
        else:
            if rows%2 == 0:
                j = rows-i-2
            else:
                j = rows-i-1
            print (' '*(rows-j-1)+symbol*(j+1))
               
symbol = '*' 
rows = int(input("请输入三角形行数,回车结束:"))
triangle(symbol,rows)


请输入三角形行数,回车结束:3
直角三角形:
  *
 **
***
等腰三角形:
  *  
 *** 
*****
其他三角形:
  *
 **
  *

In [ ]:


In [ ]:


In [ ]:


In [3]:
#将任务4中的英语名词单数变复数的函数,尽可能的考虑多种情况,重新进行实现。
def sin_to_plu(Eng_word):
    if Eng_word.endswith('s') or Eng_word.endswith('x') or Eng_word.endswith('sh') or Eng_word.endswith('ch'):
        print (Eng_word+'es')
    elif Eng_word.endswith('y'):
        print (Eng_word[0:len(Eng_word)-1]+'ies')
    else :
        print (Eng_word+'s')
        
Eng_word = input('请输入一个要转换的英语单词,回车结束  ')
sin_to_plu(Eng_word)


请输入一个要转换的英语单词,回车结束,输入‘q’结束  fish
fishes

In [ ]:


In [4]:
#写函数,根据给定符号,上底、下底、高,打印各种梯形。
def trapezium(symbol,upper_line,lower_line,height):
    print ('trapezium:')   
    for i in range(height):
        print (' '*(lower_line-upper_line-i)+symbol*(i+upper_line))
        
symbol = '*' 
upper_line = int(input("请输入梯形上底,回车结束:"))
lower_line = int(input("请输入梯形下底,回车结束:"))
height = int(input("请输入梯形的高,回车结束:"))
trapezium(symbol,upper_line,lower_line,height)


请输入梯形上底,回车结束:3
请输入梯形下底,回车结束:6
请输入梯形的高,回车结束:4
trapezium:
   ***
  ****
 *****
******

In [ ]:


In [6]:
#写函数,根据给定符号,打印各种菱形。
def rhombus(symbol,rows):
    print ('rhombus:')  
    for i in range(rows):
        if i < rows//2:
            print (' '*(rows-i-1)+symbol*(i)+'*'+symbol*(i)+' '*(rows-i-1))
        else:
            if rows%2 == 0:
                j = rows-i-2
                if (i != rows-1):
                    print (' '*(i+1)+symbol*(j)+'*'+symbol*(j)+' '*(i))
            else:
                j = rows-i-1
                print (' '*(i)+symbol*(j)+'*'+symbol*(j)+' '*(i))
symbol = '*' 
rows = int(input("请输入行数,回车结束:"))  
rhombus(symbol,rows)


请输入行数,回车结束:5
rhombus:
    *    
   ***   
  *****  
   ***   
    *    

In [ ]:


In [ ]:


In [7]:
#与本小节任务基本相同,但要求打印回文字符倒三角形。
def plalindrome(line):
    for i in range(len(line)*2,0,-1):
        if i == 1:
            print( line[0] + ' '*(len(line)*2-1))
        elif i%2 == 1:
            print(line[:i//2] + line[i//2] + line[i//2-1::-1] +'  '*(len(line)*2-i) )
        else:
            print(line[:i//2] + line[i//2-1::-1] + ' '*(len(line)*2-i) )

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

if __name__ == '__main__':
    main()


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

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [20]:
line = '天天天天天天'
for i in range(1, len(line)*2+1):
    for j in range(1,i):
        print(line[0], end='')
    print()


天
天天
天天天
天天天天
天天天天天
天天天天天天
天天天天天天天
天天天天天天天天
天天天天天天天天天
天天天天天天天天天天
天天天天天天天天天天天

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: