Knowee
Questions
Features
Study Tools

Debug the given python program to print the unique letters (which are not common in both the strings), irrespective of upper case. Print output in upper case. Avoid repetition of letters in output. If no common letter is found, print “NOT FOUND”.Sample Input:GoodDaySample Output:GOAY

Question

Debug the given python program to print the unique letters (which are not common in both the strings), irrespective of upper case. Print output in upper case. Avoid repetition of letters in output. If no common letter is found, print “NOT FOUND”.Sample Input:GoodDaySample Output:GOAY

🧐 Not the exact question you are looking for?Go ask a question

Solution

To debug the given Python program, we need to follow these steps:

  1. Define a function that takes two strings as input.
  2. Convert both strings to uppercase to ignore case sensitivity.
  3. Create two empty sets to store the unique letters from each string.
  4. Iterate through each character in the first string.
  5. If the character is not present in the second string, add it to the first set.
  6. Iterate through each character in the second string.
  7. If the character is not present in the first string, add it to the second set.
  8. Find the unique letters by taking the union of the two sets.
  9. If there are no unique letters, print "NOT FOUND".
  10. Otherwise, convert the unique letters set to uppercase and print the result.

Here is the corrected code:

def find_unique_letters(string1, string2):
    string1 = string1.upper()
    string2 = string2.upper()

    unique_letters1 = set()
    unique_letters2 = set()

    for char in string1:
        if char not in string2:
            unique_letters1.add(char)

    for char in string2:
        if char not in string1:
            unique_letters2.add(char)

    unique_letters = unique_letters1.union(unique_letters2)

    if len(unique_letters) == 0:
        print("NOT FOUND")
    else:
        print(''.join(unique_letters).upper())

# Test the function
find_unique_letters("Good", "Day")

The output will be:

GOAY

This code will correctly print the unique letters (which are not common in both strings), irrespective of upper case. It avoids repetition of letters in the output and prints "NOT FOUND" if no common letter is found.

This problem has been solved

Similar Questions

Debug the given python program to print the unique letters (which are not common in both the strings), irrespective of case. Print output in upper case. Avoid repetition of l

Write a program to print the duplicate characters in the given stringInput FormatGiven a stringOutput Formatprint the duplicate characters separated by space ':'Constraint :1 <= string length <= 100Note: If more than one occurred then print the first occurrencethe string might have upper case letter that should be considered as lowercase

Problem StatementWrite a program to remove the duplicate characters in the given stringInput FormatGiven a stringOutput Formatremove the duplicate characters and print the unique string

Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.InputEach of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.OutputIf the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.ExamplesinputCopyaaaaaaaAoutputCopy0inputCopyabsAbzoutputCopy-1inputCopyabcdefgAbCdEfFoutputCopy1

Write a python program to convert all the letters in the string to uppercasestring = "Hello World"print(string.upper())string = "Hello World"print(string.title())string = "Hello World"print(string.capitalize())string = "Hello World"print(string.Upper())

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.