Example:
Input string = "abcdef"
Input choice = "odd"
Output = "bdf"
Input string = "python"
Input choice = "even"
Output = "pto"
Input string = "abcdef"
Input choice = "3"
Output = "abde"
s=input("Enter input string:")
ch=input("Enter choice:")#read inputs from user
res=""
if ch=="odd":#if choice is odd
for i in range(1,len(s)+1):
if i%2==0:#add only even placed characters
res+=s[i-1]
elif ch=="even":#if choice is even
for i in range(1,len(s)+1):
if i%2!=0:#add only odd placed characters
res+=s[i-1]
else:
ch=int(ch)
for i in range(1,len(s)+1):
if i%ch!=0:#if i is not multiple of ch entered
res+=s[i-1]#append the characters
print("Output = ",res)
Screenshots:
The screenshots are attached below for reference.
Please follow them for output and proper indentation.
Please upvote my answer. Thank you.
.
Get Answers For Free
Most questions answered within 1 hours.