Question

Write a Python program that prompts the user to enter integer values for each of two...

Write a Python program that prompts the user to enter integer values for each of two lists. It then should displays whether the lists are of the same length, whether the elements in each list sum to the same value, and whether there are any values that occur in both lists.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# take input
L1 = input('Enter the values of first list space separated: ').split()
L1 = [int(x) for x in L1]
L2 = input('Enter the values of second list space separated: ').split()
L2 = [int(x) for x in L2]
# same length logic
if len(L1)== len(L2):
print("Both list are of same length")
else:
print("lists are of different length")
# equal sum check
if sum(L1)== sum(L2):
print("Both list have same sum value")
else:
print("lists have different sum")# find intersection b/w list
intersect = []
for x in L1:
if x in L2:
intersect.append(x)
intersect

if(len(intersect)==0):
print("Both list does not contain any common value: ")
else:
print("common values in both list are:")
for x in intersect:
print(x,)

Add a comment
Know the answer?
Add Answer to:
Write a Python program that prompts the user to enter integer values for each of two...
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
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
ADVERTISEMENT