Found 34488 Articles for Programming

Can someone help me fix this Python Program?

Arnab Chakraborty
Updated on 24-Jun-2020 07:26:01

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

Reply to user text using Python

Arnab Chakraborty
Updated on 16-Jun-2020 08:28:13

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

Count spaces, uppercase and lowercase in a sentence using C

Arnab Chakraborty
Updated on 27-Jan-2020 12:45:05

654 Views

#include int main() {    char str[100],i;    int upper = 0, lower = 0, number = 0, special = 0,whitesp=0;    printf("enter string");    gets(str);    for (i = 0; i < str[i]!='\0'; i++) {       if (str[i] >= 'A' && str[i] = 'a' && str[i] = '0' && str[i]

Java program to print ASCII value of a particular character

Lakshmi Srinivas
Updated on 13-Mar-2020 07:06:25

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

Python - How to convert this while loop to for loop?

Pythonista
Updated on 20-Jun-2020 07:41:33

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]

How can I eliminate numbers in a string in Python?

Arjun Thakur
Updated on 05-Mar-2020 11:25:01

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

How to find keith numbers using Python?

Priya Pallavi
Updated on 05-Mar-2020 11:23:28

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

How to Plot Complex Numbers in Python?

Abhinaya
Updated on 18-Jun-2020 06:38:34

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.

How to find Square root of complex numbers in Python?

Chandu yadav
Updated on 18-Jun-2020 06:40:16

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)

How to get signal names from numbers in Python?

Govinda Sai
Updated on 17-Jun-2020 14:55:56

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'}

Advertisements