#this program demonstrates the use of operator in #and other built-in functions #function search looks for item in the list # returns true if item in the list and false #otherwise #function make_list will make the list of random #numbers between 1 and 100. The amount of numbers #will be determined by the user #write a function print_triangle #that prints the following #[1] #[1, 2] #[1,2,3] #[1,2,3,4] #[1, 2, 3, 4, 5] #write a function upside_triangle #that prints the following #[1,2,3,4,5] #[1,2,3,4] #[1,2,3] #[1, 2] #[1] import random def get_list(n): values=[] for i in range(1, n+1): values.append(i) return values def print_triangle(values): for i in range(1, len(values)+1): print(values[:i]) def upside_triangle(values): n = len(values) for i in range(n): print(values[i:]) def make_list(n): values=[] for i in range(n): num=random.randint(1,100) values.append(num) return values def search(item, list_values): if(item in list_values): result=True else: result=False return result def name_list(size): names=[] for i in range(size): word=input("enter the name ") names.append(word) return names def print_menu(): print("1 - triangle") print("2 - upside down triangle") print("3 - search in list of random numbers") print("4 - seacrh in list of names") print("all other options are invalid") def menu(choice): if(choice==1): n = int(input("enter the size " )) our_list=get_list(n) print("\nhere is normal triangle\n") print_triangle(our_list) elif(choice==2): n = int(input("enter the size ")) our_list=get_list(n) print("\nhere is upside down triangle\n") upside_triangle(our_list) elif(choice==3): size=random.randint(5, 10) print("size is ", size) values=make_list(size) print("randomly generated list is") print(values) item = int(input("enter number to look ")) if(search(item, values)): print(item, "in the list") else: print(item, "not in the list") elif(choice==4): size=int(input("enter size ")) names=name_list(size) print("list of names ") print(names) item = input("enter the name ") if(search(item, names)): print(item, "in the list") else: print(item, "not in the list") else: print("invalid choice") def main(): print_menu() choice=int(input("enter your choice ")) menu(choice) main()