Found 33676 Articles for Programming

How can I remove the same element in the list by Python

Sumana Challa
Updated on 09-May-2025 10:30:40

3K+ Views

A list is a built-in Python data structure that is used to store an ordered collection of items of different data types. It often occurs that lists contain duplicate values, i.e., the same element repeating multiple times, which causes data inaccuracies. In this article, we will discuss the approaches that can be used to remove the repeated elements from a list. Using set() Using List Comprehension Using a For Loop Using Dictionary fromkeys() Using set() Function The set() function accepts an iterable ... Read More

Can someone help me fix this Python Program?

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

119 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

866 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 17-Dec-2024 03:33:55

774 Views

In this article, we will learn to print the ASCII value of a particular character in Java. ASCII (American Standard Code for Information Interchange) is a standard encoding system that assigns a unique numeric value to characters like letters, digits, and symbols. We’ll explain the concept of ASCII, demonstrate how to retrieve and display ASCII values in Java and provide practical examples to help you understand and apply this concept effectively. What Is ASCII? ASCII is a character encoding standard where each character (letters, digits, and symbols) is assigned a numeric value. For instance − ... 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 to find Square root of complex numbers in Python?

Chandu yadav
Updated on 30-Apr-2025 13:06:05

646 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

How to get signal names from numbers in Python?

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

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

How to print Narcissistic(Armstrong) Numbers with Python?

Sumana Challa
Updated on 16-May-2025 19:37:20

455 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

How to clamp floating numbers in Python?

Sumana Challa
Updated on 06-May-2025 18:53:39

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

Advertisements