Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the swapcase method for strings takes lowercase letters and capitlizes them, and then takes uppercase letters and makes them lowercase. Without using the swapcase method,
the swapcase method for strings takes lowercase letters and capitlizes them, and then takes uppercase letters and makes them lowercase. Without using the swapcase method, build your own using a function and taking in a string In [1]: string = "I like to code in Python!" print("original string:",string) swapped_string = string.swapcase) print (swapped_string) original string: I like to code in Python! i LIKE TO CODE IN PYTHON ! In [7]: from string import ascii_lowercase as lowercase from string import ascii_uppercase as uppercase print(lowercase) print(uppercase) abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ In [39]: def swapcase_function(string): output=[] for i in string: if i in range (ord("a"), ord("z")): i = ord(i) -32 output = chr(i) elif i in range (ord("A"), ord("Z")): i = ord(i)+32 output = chr(i) print (output) return output In [40]: swapcase_function("HELLO") [] Out[40]: []
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started