# 打印正方形 def squ(i): for j in range(i): for l in range(i): print('*', end='\t') print() # 打印三角形 def tri(i): for j in range(1, i + 1): for l in range(j): print('*', end='\t') print() # 输入值调用函数 user = input('输入1打印正方形,输入2打印三角形,输入0退出程序') if user == '1': squ(int(input('输入打印边长'))) elif user == '2': tri(int(input('输入打印边长'))) elif user == '0': print('退出程序')