Search code snippets, questions, articles...

Python101

afdas
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

defright_tri(n):foriinrange(n):forjinrange(1,i+2):print(j,end=" ") print()defiso_tri(n):foriinrange(n,0,-1):print(" "*(i-1),end="")forjinrange(1,2*(n+1-i)):print(j,end="") print()defkite(n):foriinrange(n,0,-1):print(" "*(i-1),end="")forjinrange(1,2*(n+1-i)):print(j,end="")print()foriinrange(1,n):print(" "*(i),end="")forjinrange(1,2*(n-i)):print(j,end="") print()defhalf_kite(n):foriinrange(n):forjinrange(1,i+2):print(j,end=" ") print()foriinrange(n-1):forjinrange(1,n-i):print(j,end=" ") print()defX(n):foriinrange(1,n+1):print(" "*(i-1),end="")forjinrange(1,2*(n-i+1)):print(j,end="")print()foriinrange(n-1,0,-1):print(" "*(i-1),end="")forjinrange(1,2*(n+1-i)):print(j,end="")print()list_pat=["Right-angled triangle", "Isosceles triangle", "Kite", "Half Kite", "X"]print("-"*50)print("Welcome to the Program")print("-"*50)print()print("-"*15+"MENU"+"-"*25)foriinrange(1,6):print(str(i)+". "+list_pat[i-1])print("6. Exit")print("-"*50)print("*"*50)pat=int(input("Give the type of pattern: "))ifpat==6:print("Exiting the program")else:print("You chose "+list_pat[pat-1])n=int(input("Give the value of n: "))if (pat==list_pat[1] orpat==list_pat[3] orpat==list_pat[4]) andn%2!=0:print("INVALID INPUT \nn has to be even for the chosen pattern") else:ifpat==1:right_tri(n)elifpat==2:iso_tri(n)elifpat==3:kite(n)elifpat==4:half_kite(n)elifpat==5:X(n)    

Was this helpful?
0 Comments