![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 27104 Articles for Server Side Programming
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
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
![Pythonista](https://www.tutorialspoint.com/assets/profiles/15003/profile/60_128639-1514576467.png)
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]
![Govinda Sai](https://www.tutorialspoint.com/assets/profiles/13542/profile/60_86497-1512650655.jpg)
331 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'}
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
282 Views
To print Narcissistic Numbers, let's first look at the definition of it. It is a number that is the sum of its own digits each raised to the power of the number of digits. For example, 1, 153, 370 are all Narcissistic numbers. You can print these numbers by running the following codedef print_narcissistic_nums(start, end): for i in range(start, end + 1): # Get the digits from the number in a list: digits = list(map(int, str(i))) total = 0 length = len(digits) for d in digits: total += d ** length ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
6K+ Views
Clamp function limits a value to a given range. Python doesn't have such a function in built. You can create this function likedef clamp(num, min_value, max_value): return max(min(num, max_value), min_value) print(clamp(5, 1, 20)) print(clamp(1, 10, 20)) print(clamp(20, 1, 10))This will give the output5 10 10
![Sravani S](https://www.tutorialspoint.com/assets/profiles/13538/profile/60_67753-1512711355.jpg)
151 Views
To print Strong Numbers, let's first look at the definition of it. It is a number that is the sum of factorials of its own digits. For example, 145 is a Strong number. First, create a function to calculate factorial:def fact(num): def factorial(n): num = 1 while n >= 1: num = num * n n = n - 1 return numYou can print these numbers by running the following code:def factorial(n): num = 1 while n >= 1: num = num * n ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
The constructor for the string class in python, ie, str can be used to convert a number to a string in python. For example, i = 10050 str_i = str(i) print(type(str_i))This will give the output:But if you want something that converts integers to words like 99 to ninety-nine, you have to use an external package or build one yourself. The pynum2word module is pretty good at this task. You can install it using$ pip install pynum2wordThen use it in the following way>>> import num2word >>> num2word.to_card(16) 'sixteen' >>> num2word.to_card(23) 'twenty-three' >>> num2word.to_card(1223) 'one thousand, two hundred and twenty-three'Read More
![Ramu Prasad](https://www.tutorialspoint.com/assets/profiles/13539/profile/60_87996-1512650215.jpg)
2K+ Views
You can get the XOR of any type of numbers using the ^ operator. Specifically for hex numbers, you can use:a = 0x12ef b = 0xabcd print(hex(a ^ b))This will give the output:0xb922The 0x at the beginning of the numbers implies that the number is in hex representation. You can use the ^ operator for other integer representations as well.
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
908 Views
You can divide large numbers in python 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. You would be better off using a numeric computation library like bigfloat to perform such operations.You can read more about floating point issues that you might face with precision on https://docs.python.org/3/tutorial/floatingpoint.html
![Ankitha Reddy](https://www.tutorialspoint.com/assets/profiles/13550/profile/60_73963-1512711511.jpg)
2K+ 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. For example, a = 15421681351 b = 6184685413848 print(a * b) This will give the output − 95378247708541418748648