Abi, an aspiring programmer, is intrigued by character manipulation. She seeks your assistance to write a program that takes two characters as inputs and implements a function called swapCase(), swaps their positions along with case conversion, and prints the modified characters.Input format :The input consists of two space-separated characters.Output format :The output displays the two space-separated characters, representing the modified values after swapping and converting cases.Refer to the sample output for formatting specifications.Code constraints :Input characters should be 'a' to 'z' or 'A' to 'Z'.Sample test cases :Input 1 :a ZOutput 1 :z AInput 2 :d kOutput 2 :K DInput 3 :K sOutput 3 :S k
Question
Abi, an aspiring programmer, is intrigued by character manipulation. She seeks your assistance to write a program that takes two characters as inputs and implements a function called swapCase(), swaps their positions along with case conversion, and prints the modified characters.Input format :The input consists of two space-separated characters.Output format :The output displays the two space-separated characters, representing the modified values after swapping and converting cases.Refer to the sample output for formatting specifications.Code constraints :Input characters should be 'a' to 'z' or 'A' to 'Z'.Sample test cases :Input 1 :a ZOutput 1 :z AInput 2 :d kOutput 2 :K DInput 3 :K sOutput 3 :S k
Solution
Here is a Python solution for the problem:
def swapCase(char1, char2):
# Swap the characters and convert their cases
swapped_chars = char2.swapcase() + ' ' + char1.swapcase()
return swapped_chars
# Test the function with the provided test cases
print(swapCase('a', 'Z')) # Expected output: 'z A'
print(swapCase('d', 'k')) # Expected output: 'K D'
print(swapCase('K', 's')) # Expected output: 'S k'
This program defines a function swapCase() that takes two characters as inputs. It uses the swapcase() method to convert the case of each character (i.e., lowercase to uppercase and vice versa), and then swaps their positions. The function returns the modified characters as a string, separated by a space.
The program then tests the function with the provided test cases. The expected outputs are comments next to each test case.
Similar Questions
Write a program that takes a string of lowercase characters as input and prints it in uppercase, reversed.
Implement a function to swap the odd and even-indexed characters in a given string.swap_odd_even_chars(String text): that takes a string as input and returns the odd and even-indexed characters swapped string as output.Example - 1 : Input:String text = “abcdefgh”swap_odd_even_chars(text) Output: 'badcfehg'
Write a program that converts strings of all uppercase characters into strings of all lowercase and viceversa
String Operations Send Feedback Problem Statement: A sentence can have different versions due to variations in character cases, such as 'dog', 'Dog', and 'DOG'. The computer will treat these differently to ensure that all variations are treated equally. Write a function convert_to_lowercase that takes a sentence as input and converts all characters in the sentence to lowercase. Input: The convert_to_lowercase function takes a sentence (string) as input. Output: The function returns a string with all characters converted to lowercase. Sample Input 1: sentence = "Hello, World!" convert_to_lowercase(sentence) Return Output 1: "hello, world!" Sample Input 2: sentence = "Convert ME to lowercase" convert_to_lowercase(sentence) Return Output 2: "convert me to lowercase"
Arun is working on a program to swap the values of two variables, a and b, without using a temporary variable. Write a program to help Arun accomplish this task.Input format :The first line of input is an integer value a.The second line of input is an integer value b.Output format :The output prints the values of a and b after swapping. Refer to the sample output for the formatting specifications.
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.