205k views
5 votes
python Write a program that asks a user to type in two strings and that prints •the characters that occur in both strings. •the characters that occur in one string but not the other. •the letters that don’t occur in either string. Use the set function to turn a string into a set of characters.

1 Answer

5 votes

Answer:

see explanation

Step-by-step explanation:

#we first get the elements as inputs

x = input("enter string A :")

y = input("enter string B :")

#then we make independent sets with each

x = set(x)

y = set(y)

#then the intersection of the two sets

intersection = set.intersection(x,y)

#another set for the alphabet

#we use set.difference to get the elements present in x and not in y, and

#viceversa, finally we get the difference between the alphabet and the #intersection of the elements in our strings

z = set('abcdefghijklmnopqrstuvwxyz')

print('\\repeated :\\',intersection)

print('differences :\\',' Items in A and not B\\',

set.difference(x,y),'\\Items in B and not A\\',

set.difference(y,x))

print('\\Items in neither :\\',set.difference(z,intersection))