Define a function calles myfunc which takes a string and returns a matching strin where every even letter is in capital and odd letter in lower case
Answers
Answer:
def myfunc(word):
result = ""
index = 0
for letter in word:
if index % 2 == 0:
result += letter.lower()
else:
result += letter.upper()
return result
index +=1
Explanation:
Python code for the given problem statement is given below
Code:
#defining myfunc
def myfunc(string):
new_str="" #initialising a new string
for i in range(len(string)): #iterating over the given string
if i%2 == 0: #checking whether divisible by 2
#since it is even letter, capital letter is added to new string
new_str+=string[i].upper()
else: #if not divisible by 2
#since it is odd letter, small letter is added to new string
new_str+=string[i].lower()
return new_str #returning the required string
#main function
string = input() #taking string input from user
print("Output is " +myfunc(string)) #print output of myfunc
Output:
Hello World
Output is HeLlO WoRlD
#SPJ3