Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 100+ Python challenging programming exercises.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2371,5 +2371,25 @@ solutions=solve(numheads,numlegs)
print solutions

#----------------------------------------#
Level: Medium

Question:

Given a sentence, reverse and swap the case of the letters within the sentence.

Example:
1. "hEllo, I aM A cAt" => "CaT a Am i HeLLO,"
2. "THiS IS a sEnTENce." => "SeNtenCE. A is thIs"

Hints: Use reversed(), swapcase(), and .join() to solve this problem.

Answer:

def stringReverse_and_swapCase(string):
sen = string.split()
sen = list(reversed(sen))
sen = " ".join(sen)
sen = sen.swapcase()

stringReverse_and_swapCase(string)
#----------------------------------------#