Thursday, 9 December 2021

Python Programming

 Q1.The program takes two strings and displays which letters are in the first string but not in the second string.

Program:

my_str_1 = input("Enter the first string : ")
my_str_2 = input("Enter the second string : ")
my_result = list(set(my_str_1)-set(my_str_2))
print("The letters in first string but not in second string :")
for i in my_result:
   print(i)

Output:


                Download Code


Q2.Write a Python Program to find the union of two lists.

Sample Input:

lst1=[10,20,30,40,30,50,60]

lst2=[10,15,20,30,25,25]

Output:

lst3=[10,20,30,40,50,60,15,25]  # or in any other order


Program:

# Python program to illustrate union
# Maintained repetition
def Union(lst1, lst2):
    final_list = lst1 + lst2
    return final_list

# Driver Code
lst1 = [10,20,30,40,30,50,60]
lst2 = [10,15,20,30,25,25]
print(Union(lst1, lst2))

Output:


                Download Code

No comments:

Post a Comment

Mario-Game-Program-In-Python

  Mario-Game-Program-In-Python  Simple Mario Game:   Code: import pygame import sys pygame.init() WINDOW_WIDTH = 1200 WINDOW_HEIGHT = 600 FP...