
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
Python Articles - Page 952 of 1048

2K+ Views
You can solve this problem by using if-elif-else statements. And to make it like, it will ask for a valid option until the given option is on the list, we can use while loops. When the option is valid, then break the loop, otherwise, it will ask for the input repeatedly.You should take the input as an integer, for that you need to typecast the input to an integer using int() method.ExamplePlease check the code to follow the given points.print("Come-on in. Need help with any bags?") while True: # loop is used to take option until it is not valid. ... Read More

1K+ Views
Usin count() function in itertools module gives an iterator of evenly spaced values. The function takes two parameters. start is by default 0 and step is by default 1. Using defaults will generate infinite iterator. Use break to terminate loop.import itertools percentNumbers = [ ] finish = "n" num = "0" for x in itertools.count() : num = input("enter the mark : ") num = float(num) percentNumbers.append(num) finish = input("stop? (y/n) ") if finish=='y':break print(percentNumbers)Sample output of the above scriptenter the mark : 11 stop? (y/n) enter the mark : 22 stop? (y/n) enter the mark : 33 stop? (y/n) y [11.0, 22.0, 33.0]

657 Views
Complex numbers are numbers that have both real and imaginary components in the structure, a+bi. You can find the square root of complex numbers in Python using the cmath module. This module in Python is exclusively used to deal with complex numbers.Square Root of Complex Numbers Using cmath.sqrt() The cmath.sqrt() function is a part of Python's cmath module, that takes a number which is an integer or float (real or complex) and returns the complex square root of x. Below are some examples of scenarios where the function can be used - Example - Basic Complex Number In the below ... Read More

530 Views
There is no straightforward way of getting signal names from numbers in python. You can use the signal module to get all its attributes. Then use this dict to filter the variables that start with SIG and finally store them in a dice. For example,Exampleimport signal sig_items = reversed(sorted(signal.__dict__.items())) final = dict((k, v) for v, k in sig_items if v.startswith('SIG') and not v.startswith('SIG_')) print(final)OutputThis will give the output:{: 'SIGTERM', : 'SIGSEGV', : 'SIGINT', : 'SIGILL', : 'SIGFPE', : 'SIGBREAK', : 'SIGABRT'}

464 Views
A narcissistic number (also known as an Armstrong number) is a number that equals the sum of its digits, each raised to the power of the number of digits. For example, 370 - 33+73+03 = 370. The algorithm to check for an Armstrong number is as follows - Determine the number of digits for the mentioned number. Extract each digit and calculate the power of that digit with the exponent equal to the number of digits. Calculate the sum of the power. Compare ... Read More

6K+ Views
Clamping refers to limiting a number to a specific range, i.e., making sure that the number lies between the minimum and maximum value mentioned. This method is used in applications like graphics and statistical computations, as it requires the data to stick to specific limits. Clamping Floating Numbers in Python The following are some of the approaches to clamp floating numbers in Python - Creating a User-Defined Function Since Python has no built-in clamp function, in the following program, we will create our clamp() function, which takes three parameters - n (number to be clamped), min (minimum value), and max (maximum ... Read More

2K+ Views
The given task is to convert the numerical values to their respective word representation (i.e, we need to spell the numbers in text ). For example, if the given numbers are 1, 2, 29, the resultant values would be: one, two, twenty-nine, respectively. We can do so, using the function(s) available in the num2word library. Converting Numbers to Words Using num2word() The num2words() is a function of the Python library with the same name (num2words). This is used to convert numbers like 56 to words like fifty-six. In addition to the numerical parameters, this function accepts two optional parameters - ... Read More

3K+ Views
The bitwise XOR is a binary operation in which we compare two binary numbers bit by bit and return the value "1" if the bits are not same, and 0 if they are the same. The XOR(exclusive OR) operation follows the below rules - A B A ⊕ B ... Read More

1K+ Views
Python allows you to perform the basic mathematical operations like addition, subtraction, multiplication, and division on large numbers as Python's integers are arbitrary-precision, hence there is no limit on their size.You can divide large numbers as you would normally do. But this has a lot of precision issues as such operations cannot be guaranteed to be precise, as it might slow down the language.Usually, dividing large numbers results in a floating-point number, which cannot be precise since Python's float can only accurately be represented up to 15-17 decimal digits.To overcome this issue, we can perform division operation using division operator ... Read More

3K+ Views
You can multiply large numbers in Python directly without worrying about speed. Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate. As long as you have version 2.5 or better, just perform standard math operations, and any number which exceeds the boundaries of 32-bit math will be automatically (and transparently) converted to a bignum. To multiply large numbers in Python, we can use the basic multiplication operator or use the fractions ... Read More