Answered step by step
Verified Expert Solution
Link Copied!

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,

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions