From 90959b6b2331fa55fd98c750ec2ee73d22268a88 Mon Sep 17 00:00:00 2001 From: Rohit Barua <83600150+Rohit-beep-droid@users.noreply.github.com> Date: Sun, 23 May 2021 18:53:11 -0400 Subject: [PATCH] Update 100+ Python challenging programming exercises.txt A sentence reversing function that also swaps the case of the letters within the sentence. It is a medium level difficulty problem for beginners. --- ...thon challenging programming exercises.txt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 97af5aaf..c56756b3 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -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) +#----------------------------------------#