Question

In Python, how do I add A to each number in set X? A = 2...

In Python, how do I add A to each number in set X?

A = 2

X = {-2, 3}

Desired Output: X = {0, 5}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
A = 2
X = {-2, 3}
result = set()

for num in X:
    result.add(num + A)
X = result

print("X =", X)

Add a comment
Know the answer?
Add Answer to:
In Python, how do I add A to each number in set X? A = 2...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In python: Not sure how to do a Collatz function. Remember the Collatz function? If x...

    In python: Not sure how to do a Collatz function. Remember the Collatz function? If x is odd, then collatz(x) = 3 ⋅ x + 1 but if x is even then collatz(x) = x/2. (remember to use // to divide by 2) Start by writing a Collatz() function that returns the value for a given input. Test this function for all numbers from 1 to 10. Next write a Collatz2() method. This method should take in a single number...

  • How do I add the space that this Zybooks code keeps asking me to add? 5.13...

    How do I add the space that this Zybooks code keeps asking me to add? 5.13 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5...

  • Python problem: How do you include the number that you are trying to process if it's...

    Python problem: How do you include the number that you are trying to process if it's the sentinel?  This is my solution won't include -999 in the process, but I am not sure how do this... # write a program that prints out the average of # the negative numbers in the list that appear before a -999 is detected. def main(): MyList = [ 23, -45, 6, -23, -9, 77, 54, -54, 21, -2, 8, -3, -23, 45, 93, -43,...

  • 1. Give the Python program that computes the square of a number. The number is passed...

    1. Give the Python program that computes the square of a number. The number is passed to the function as a parameter. The output is the square of this number. For example, the function can be used as shown below . . . . n = s q u a r e ( 7 ) . . . 2. Another very useful feature of Python is looping, which is more flexible than that available in BB. For example: while i...

  • Python: Could you please say step by step how the output is coming? I understand about...

    Python: Could you please say step by step how the output is coming? I understand about importing and getting random number but how the inner loop is working? Code: import random li1 = [[random.randrange(5) for i in range(3)] for j in range(4)] print("First output : {}".format(li1)) ncol = 4 nrow = 5 li2 = [ [random.randrange(2) for i in range(ncol) ] for j in range(nrow) ] print("Second output : {}".format(li2)) Output: First output : [[3, 2, 4], [2, 3, 2],...

  • IN PYTHON Write a program that, given a set of words in a list, calculate how...

    IN PYTHON Write a program that, given a set of words in a list, calculate how many words begin with the letter you capture. Entry: 5 words and 1 letter Output: # of words that have the letter. IMPORTANT NOTE: Your program should not include an input message: you are only going to capture the 5 words and finally the letter you want to find and as an output message you must indicate only the number of words that begin...

  • python how can I print "Hello 55!" how can i add the exclamation mark at the...

    python how can I print "Hello 55!" how can i add the exclamation mark at the end using a comma to add my variable? name = 55 print( "Hello", name )  

  • In python, how do you create an array of unknown dimensional size? I want to create...

    In python, how do you create an array of unknown dimensional size? I want to create an array of unknown dimensional size based on a number I recieve. To elaborate, let's say n = 2, it will output a 3D array {true, true, true}. If n = 3, then its output will be a 4D array {true, true, true, true}. Whatever the n value is, the return value will be an array of n + 1 dimensional size. How would...

  • please code in python 1. Write a program to request the user enter a desired number...

    please code in python 1. Write a program to request the user enter a desired number of values. Create a loop to load the desired number of user-specified values into a list. Create two lists with the same values but generated in different ways. On list will be originally initialized to have the desired length before entering the loop. The other list will begin empty and values be appended for every iteration of the loop. Output from the program should...

  • Hi May I ask how can I do this: provided a list [1,2,3,4] and return a...

    Hi May I ask how can I do this: provided a list [1,2,3,4] and return a list as each number added the number before it, for example, the final list should return as [(1+0),(1+2),(1+2+3),(1+2+3+4)] = [1,3,6,10] please do in python 3.7, thank you!!!

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT