- Trending Categories
- 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 34488 Articles for Programming
61 Views
The first problem u are getting in the bold portion is due to non-indent block, put one indentation there.second problem is name variable is not definedfollowing is the corrected one -print ("Come-on in. Need help with any bags?") bag=input ('(1) Yes please (2) Nah, thanks (3) Ill get em later TYPE THE NUMBER ONLY') if bag == ('1'): print ("Ok, ill be right there!") if bag == ('2'): print ("Okee, see ya inside. Heh, how rude of me? I'm Daniel by the way, ya?") name="Daniel" print (name + ": Um, Names " + name) print ("Dan: K, nice too ... Read More
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
468 Views
ASCII stands for American Standard Code for Information Interchange. There are 128 standard ASCII codes, each of which can be represented by a 7-digit binary number: 0000000 through 1111111.If you try to store a character into an integer value it stores the ASCII value of the respective character.Exampleimport java.util.Scanner; public class ASCIIValue { public static void main(String args[]){ System.out.println("Enter a character ::"); Scanner sc = new Scanner(System.in); char ch = sc.next().charAt(0); int asciiValue = ch; System.out.println("ASCII value of the given character is ::"+asciiValue); ... 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]
122 Views
You can create an array to keep track of all non digit characters in a string. Then finally join this array using "".join method. examplemy_str = 'qwerty123asdf32' non_digits = [] for c in my_str: if not c.isdigit(): non_digits.append(c) result = ''.join(non_digits) print(result)OutputThis will give the outputqwertyasdfexampleYou can also achieve this using a python list comprehension in a single line. my_str = 'qwerty123asdf32' result = ''.join([c for c in my_str if not c.isdigit()]) print(result)OutputThis will give the outputqwertyasdf
487 Views
You can use the following code to find if a number is a keith number in python −Exampledef is_keith_number(n): # Find sum of digits by first getting an array of all digits then adding them c = str(n) a = list(map(int, c)) b = sum(a) # Now check if the number is a keith number # For example, 14 is a keith number because: # 1+4 = 5 # 4+5 = 9 # 5+9 = 14 while b < n: a = a[1:] + [b] b = sum(a) return (b == n) & (len(c) > 1) print(is_keith_number(14))OutputThis will give the output −True
2K+ Views
You can plot complex numbers on a polar plot. If you have an array of complex numbers, you can plot it using:import matplotlib.pyplot as plt import numpy as np cnums = np.arange(5) + 1j * np.arange(6,11) X = [x.real for x in cnums] Y = [x.imag for x in cnums] plt.scatter(X,Y, color='red') plt.show()This will plot a graph of the numbers in a complex plane.
444 Views
You can find the Square root of complex numbers in Python using the cmath library. The cmath library in python is a library for dealing with complex numbers. You can use it as follows to find the square root −Examplefrom cmath import sqrta = 0.2 + 0.5j print(sqrt(a))OutputThis will give the output (0.6076662244659689+0.4114100635092987j)
341 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'}