When it is required to find all the numbers that are odd, and are palindromes and lie between a given range of values, and it has been told that recursion can’t be used, then, list comprehension, and ‘%’ operator can be used to achieve the same.Palindromes are string that are same when they are read in either way- left to right and right to left.Below is a demonstration for the same −Example Live Demomy_list = [] lower_limit = 5 upper_limit = 189 print("The lower limit is : ") print(lower_limit) print("The upper limit is : ") print(upper_limit) my_list = [x for x ... Read More
When it is required to implement a binomial tree in Python, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to perform calculator operations.Below is a demonstration for the same −Example Live Democlass binomial_tree: def __init__(self, key): self.key = key self.children = [] self.order = 0 def add_at_end(self, t): self.children.append(t) self.order = self.order + 1 my_tree = ... Read More
When it is required to split the list, and then add this first part to the end of the list, a simple iteration through the list and list slicing is required.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a demonstration for the same −Example Live Demodef split_list(my_list, n_val, k_val): for i in range(0, k_val): first_val = my_list[0] for k in range(0, n_val-1): my_list[k] = my_list[k + 1] my_list[n_val-1] = first_val my_list ... Read More
When it is required to create a class to get all the possible subsets of integers from a list, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to perform calculator operations.Below is a demonstration for the same −Example Live Democlass get_subset: def sort_list(self, my_list): return self. subset_find([], sorted(my_list)) def subset_find(self, curr, my_list): if my_list: return self. subset_find(curr, my_list[1:]) + self. subset_find(curr ... Read More
When it is required to create a class that has a method that accepts a string from the user, and another method that prints the string, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to perform calculator operations.Below is a demonstration for the same −Example Live Democlass print_it(): def __init__(self): self.string = "" def get_data(self): self.string=input("Enter the string : ") def put_data(self): ... Read More
When it is required to create a class that performs calculator operations, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to perform calculator operations.Below is a demonstration for the same −Example Live Democlass calculator_implementation(): def __init__(self, in_1, in_2): self.a=in_1 self.b=in_2 def add_vals(self): return self.a+self.b def multiply_vals(self): return self.a*self.b def divide_vals(self): return self.a/self.b def ... Read More
The CSS ::first-line pseudo-element helps us style first line of an elementThe following examples illustrate CSS ::first-line pseudo-element.Example Live Demo body { text-align: center; background-color: darkorchid; } ::first-line { font-size: 2em; color: black; font-weight: bold; text-shadow: 0 -10px grey; } Donec rutrum a erat vitae interdum. Donec suscipit orci sed arcu cursus imperdiet. Duis consequat aliquet leo, quis aliquam ex vehicula in. Vivamus placerat tincidunt hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque semper ex eget nulla consectetur varius. Integer a dolor leo. Donec ... Read More
Using the CSS pointer-events property we can control whether a mouse and touch are allowed on an element.The syntax of CSS pointer-events property is as follows −pointer-events: auto|none;Above, auto is default. Element reacts to pointer events, whereasnone: Element does not react to pointer eventsExampleThe following examples illustrate CSS pointer-events property. Live Demo a { margin: 10vh; pointer-events: none; } a:last-of-type { pointer-events: auto; } No pointer event here Automatic pointer event here OutputThis will produce the following result −Example Live Demo select { margin: 10vh; pointer-events: none; ... Read More
We can store extra information about elements using data-* attribute. The following examples illustrate CSS data-* attribute.Example Live Demo dl { margin: 2%; } p { width: 60%; background-color: lightgreen; padding: 2%; color: white; text-align: center; } dt { font-weight: bold; } dt:hover { cursor: pointer; } dd { font-style: italic; } Tea Hot Spicy Tea or Ice Lemon Tea Toast Hot Garlic Butter Toast (hover over food item) function showDescription(food) { let foodType = food.getAttribute("data-food-type"); document.querySelector('p').textContent = ("We ... Read More
We can create a customized checkmark using CSS. The following examples illustrate this effect −Example Live Demo div { margin: 2%; position: relative; width: 40px; height: 40px; box-shadow: inset 0 0 12px lightblue; } div::before { content: ""; position: absolute; width: 8px; top: 50%; height: 50%; border-radius: 2px; background-color: rgb(123, 45, 20); transform: translateX(12px) rotate(-45deg); transform-origin: left bottom; z-index: +1; } div::after { content: ""; position: absolute; bottom: 0; height: 8px; width: 100%; border-radius: 2px; background-color: rgb(200, ... Read More