Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2491 of 3366
311 Views
Create a Python ListExampleC:\Py3Project>howdoi create a python listOutputRunning the above code gives us the following result −>>> l = [None] * 10 >>> l [None, None, None, None, None, None, None, None, None, None]Printing Today’s DateExamplec:\python3>howdoi print today's date in pythonOutputRunning the above code gives us the following result −for date in mylist : print str(date)Examplec:\python3>howdoi create fibonnaci series in pythonOutputRunning the above code gives us the following result −def F(n): if n == 0: return 0 elif n == 1: return 1 else: return F(n-1)+F(n-2)Examplec:\python3>howdoi use calendar in javascriptOutputRunning the above code gives us the following ... Read More
1K+ Views
In python the print statement adds a new line character by default. So when we have multiple print statements the output from each of them is printed in multiple lines as you can see in the example below. Our goal is to print them in a single line and use some special parameters to the print function to achieve that.Normal Print()The below example prints multiple statements with new lines in each of them.Exampleprint("Apple") print("Mango") print("Banana")OutputRunning the above code gives us the following result −Apple Mango BananaUsing end ParameterWe can use the end parameter to use a specific character at the ... Read More
1K+ Views
Google offers many python packages which minimize the effort to write python code to get data from google services. One such package is google images download. It takes in the key words as parameters and locates the images with those keywords.ExampleIn the below example we limit the number of images to 5 and also allow the program to print the urls from where the files were generated.from google_images_download import google_images_download #instantiate the class response = google_images_download.googleimagesdownload() arguments = {"keywords":"lilly, hills", "limit":5, "print_urls":True} paths = response.download(arguments) #print complete paths to the downloaded images print(paths)OutputRunning the above code gives us the following ... Read More
6K+ Views
In Python sometimes we have link the output and we want to clear the screen in the cell prompt we can clear the screen by pressing Control + l . But there are situations when we need to clear the screen programmatically depending on the amount of output from the program and how we want to format the output. In such case we need to put some commands in the python script which will clear the screen as and when needed by the program.We need the system() from the OS module of python to clear up the screen. For different ... Read More
174K+ Views
There is a need to generate random numbers when studying a model or behavior of a program for different range of values. Python can generate such random numbers by using the random module. In the below examples we will first see how to generate a single random number and then extend it to generate a list of random numbers.Generating a Single Random NumberThe random() method in random module generates a float number between 0 and 1.Exampleimport random n = random.random() print(n)OutputRunning the above code gives us the following result −0.2112200Generating Number in a RangeThe randint() method generates a integer between ... Read More
2K+ Views
Greatest common divisor or gcd is a mathematical expression to find the highest number which can divide both the numbers whose gcd has to be found with the resulting remainder as zero. It has many mathematical applications. Python has a inbuilt gcd function in the math module which can be used for this purpose.gcd()It accepts two integers as parameter and returns the integer which is the gcd value.SyntaxSyntax: gcd(x, y) Where x and y are positive integers.Example of gcd()In the below example we print the result of gcd of a pair of integers.import math print ("GCD of 75 and 30 ... Read More
382 Views
This function helps in converting a mutable list to an immutable one. This is needed when we have declared a list whose items are changeable but after certain steps we want to stop allowing the elements in it to change. In such scenario, we apply the frozenset() function as shown below.SyntaxSyntax: frozenset(iterable_object_name)In the below example we take a list, change its element and print it. Then in the next step we apply the frozenset function, and try changing the element again. In the second step we get the error showing that the list can not be modified anymore.Example# Before applying ... Read More
1K+ Views
C programming puzzles are small but tricky coding problems, which are designed to challenge and to understand the C programming language in a better way. Problem Statement We are given two numbers, and our task is to combine them in such a way that the second integer is placed before the first integer, resulting in a single combined integer. But here, we are not allowed to use any logical, arithmetic, string-related operations, or any pre-defined functions. Consider the following input/output scenarios to understand the puzzle statement better: Scenario 1 Input: 12, 54 Output: 5412 Explanation: Here, the second ... Read More
2K+ Views
These two methods are part of python math module which helps in getting the nearest integer values of a fractional number.floor()It accepts a number with decimal as parameter and returns the integer which is smaller than the number itself.SyntaxSyntax: floor(x) Where x is a numeric valueExample of floor()In the below example we take different types of numeric values like, integer, positive decimal and negative decimal and apply the floor function to them. We get the nearest integer which is less than the numeric value supplied.import math x, y, z = 21 , -23.6 , 14.2 print("The value of ", x, ... Read More
262 Views
This an array based puzzle that need you to change all the numbers of an array the contains two elements to 0. One element of the array is 0 and other may or may not be 0.To solve this puzzle the program needs to find the non-zero element and change in to 0.Their are the following constraints that are needed to solve the boolean array puzzle −Allowed operation is complement, other operations are not allowed.Loops and conditional statements are not allowed.Direct assignment is also not allowed.PROGRAM TO SOLVE BOOLEAN ARRAY PUZZLE#include using namespace std; void makeZero(int a[2]) { a[ ... Read More