Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here is the original question: Create a file called alternative.py Write a program that reads in a string and makes each alternate character into an
Here is the original question:
Create a file called alternative.py
Write a program that reads in a string and makes each alternate
character into an upper case character and each other alternate character
a lower case character.
eg The string Hello World would become HeLlO WoRlD
Now, try starting with the same string but making each alternative word
lower and upper case.
eg The string: I am learning to code would become i AM learning
TO code
Tip: Using the split and join functions will help you here.
I received the following feedback and need help with improving my code please:
Please note that for the second task, you are supposed to use the same string that you used for task instead of asking the user for another user input. That is the only missing requirement in this program. So basically making each alternative word lower and upper case for the same input string from task one.
Choosing good names for variables in coding is important. It makes the code easier to read and understand. Good names are clear and meaningful also help avoid mistakes and make it easier to improve or change the code later. While this is a small program, for larger programs you must do this, but you need to practice while on small programs. Please notice the c in line i in line sw in line and s in line these are not descriptive at all.
Please can someone help asap?alternative.py
C: Users User
#First, define a function called alternatecase which will take in a single input argument st which is a string
def alternatecasest:
#use for loop to iterate through each character in the list, and check the index to allocate case.
#ensure whitespace is not included
flag True
result
for in st:
if flag:
result cupper
else:
result c lower
if :
flag not flag
return result
SW inputPlease enter your sentence for alternate letter case change:
printalternatecasesw #use print command to execute
#define a function called alternatecase which will take in a single input argument st which is a string
def alternatewordst:
words stsplit #use builtin "split method to separate the input string into a list of individual words
for i in rangelenwords:
if :
words i words iupper
else:
words i words
return joinwords #builtin "join method used to concatenate the modified words into a single string and return the result
s inputPlease enter your sentence for alternate word case change:
printalternatewords #use print command to execute
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