Turtle Graphics Using Python

Pradeep Elance
Updated on 23-Dec-2019 10:33:05

29K+ Views

Turtle is a Python library to draw graphics. After we import Turtle we can give commands like forward, backward, right, left etc. This commands will draw different shapes when we. When We combine Search commands we can create many nice graphics in the below example we will see some simple scenarios and then some Complex ones where nice graphics is created.Simple Turtle Commandsforward(10)  It moves the turtle (arrow) forward by 10 pixels.backward(5)  It moves the turtle (arrow) backward by 5 pixels right(35)  It moves the turtle (arrow) clockwise by an angle of 35 degrees.left(55)  It moves the turtle (arrow) counter-clockwise by ... Read More

Get Index of First Element Greater Than K in Python

Pradeep Elance
Updated on 23-Dec-2019 10:25:05

2K+ Views

The values of items in a python list are not necessarily in any sorted order. More over there may be situation when we are interested only in certain values greater than a specific value. In this article we will see how we can get theUsing EnumerationUsing enumeration we get both the index and value of the elements in the list. Then we apply the greater than condition to get only the first element where the condition is satisfied. The next function goes through each list element one by one.Example Live DemoList = [21, 10, 24, 40.5, 11] print("Given list: " + ... Read More

Get Sum of Tuples Having Same First Value in Python

Pradeep Elance
Updated on 23-Dec-2019 10:22:16

532 Views

Tuples are python collections or arrays which are ordered but unchangeable. If we get a number of tuples where the first element is the same, then we may have a scenario when we need to add the second elements of those tuples whose first elements are equal.Using map and for loopIn this method we will first consider a list made up of tuples. Then convert them to dictionary so that we can associate the elements in the tuple as key value pair. Then we apply the for loop with summing the value for each key o the dictionary. Finally use ... Read More

Python Geometry Method in Tkinter

Pradeep Elance
Updated on 23-Dec-2019 10:11:32

9K+ Views

Python has capability to create GUI applications using the Tkinter library. The library provides many methods useful for GUI applications. The geometry method is a fundamental one which decides the size, position and some other attributes of the screen layout we are going to create.Example - 1In the below program we create a window of size 22x200 pixels using the geometry method. Then we add a button to it and decide button position in the window using the side and pady options.Examplefrom tkinter import * base = Tk() base.geometry('200x200') stud = Button(base, text = 'Tutorialspoint', font =('Courier', 14, 'bold')) stud.pack(side ... Read More

Check If Two Lists Have Any Element in Common in Python

Pradeep Elance
Updated on 23-Dec-2019 10:09:16

4K+ Views

During manipulating data using python lists, we come across a situation where we need to know if two lists are entirely different from each other or they have any element in common. This can be found out by comparing the elements in the two lists with the below approaches decribed.Using InIn a for loop we use the in clause to check in an element is present in the list or not. We will stretch this logic to compare the elements of the lists by choosing an element from first list and checking its presence in the second list. So we ... Read More

Get Screen's Height and Width Using Tkinter in Python

Pradeep Elance
Updated on 23-Dec-2019 10:00:44

504 Views

Tkinter is the library which gives GUI programming capability to python programs. As part of GUI creation we need to create screen layouts of different sizes and depth. In this program we will see how to calculate the size of a screen in terms of pixels as well as in mm. We can also get the depth of the screen in pixels. There are various methods available as part of Tkinter which we use for this.Examplefrom tkinter import * # creating tkinter window base = Tk() #screen's length and width in pixels and mm length_1= base.winfo_screenheight() width_1= base.winfo_screenwidth() length_2 = ... Read More

Find the Smallest Number in a List in Python

Pavitra
Updated on 23-Dec-2019 09:30:14

384 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given al list, we need to display the smallest number available in the listHere we can either sort the list and get the smallest element or use the built-in min() function to get the smallest element.Now let’s observe the concept in the implementation below −Example Live Demolist1 = [101, 120, 104, 145, 99] # sorting using built-in function list1.sort() print("Smallest element is:", list1[0])OutputSmallest element is: 99All the variables are declared in the local scope and their references are seen in the figure ... Read More

Priority Queue in C++ Standard Template Library (STL)

Sunidhi Bansal
Updated on 23-Dec-2019 09:29:44

511 Views

Priority queue is an abstract data type for storing a collection of prioritized elements that supports insertion and deletion of an element based upon their priorities, that is, the element with first priority can be removed at any time. The priority queue doesn’t stores elements in linear fashion with respect to their locations like in Stacks, Queues, List, etc. The priority queue ADT(abstract data type) stores elements based upon their priorities.Priority Queue supports the following functions −Size() − it is used to calculate the size of the priority queue as it returns the number of elements in it.Empty() − it return ... Read More

Array Pad Function in PHP

Chandu yadav
Updated on 23-Dec-2019 08:50:44

501 Views

The array_pad() function inserts a specified number of items, with a specified value, to an array. It returns array with new elements. If size is positive then the array is padded on the right, if it's negative then the padding is done on the left.Syntaxarray_pad(arr, size, value)Parametersarr − the arraysize − total elements in the resultant arrayvalue − the value to pad and it should be less than the size of arrReturnThe array_pad() function returns array with new elements. If size is positive then the array is padded on the right, if it's negative then the padding is done on ... Read More

Find the Largest Number in a List using Python

Pavitra
Updated on 23-Dec-2019 08:09:45

1K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to calculate the largest element of the list.Here we will take the help of built-in functions to reach the solution of the problem statementUsing sort() functionExample# list list1 = [23, 1, 32, 67, 2, 34, 12] # sorting list1.sort() # printing the last element print("Largest element is:", list1[-1])OutputLargest in given array is 67Using max() functionExample Live Demo# list list1 = [23, 1, 32, 67, 2, 34, 12] # printing the maximum element print("Largest element is:", max(list1))OutputLargest in given ... Read More

Advertisements