-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcap_small_1-1.py
More file actions
43 lines (37 loc) · 984 Bytes
/
cap_small_1-1.py
File metadata and controls
43 lines (37 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Write a function to convert a given string to Spongecase.
Spongecase is a style of text where letters alternately appear in lower and upper case.
For example, the word Spongecase in spongecase would be sPoNgEcAsE.
input :"programizpro123"
output:pRoGrAmTzPr0123
Input:learn to code
output:lEaRn To CoDe
"""
# def Spongecase(string):
# new=''
# for i in range(0 , len(string)):
# if (i%2!=0):
# new=new+string[i].upper()
#
# else:
# new =new+string[i].lower()
#
# return new
# s=input("Enter a string :")
# print(Spongecase(s))
# s="hello"
# print(s[2])
def Spongecase(text):
result = []
i = 0
for char in text:
if char.isalpha():
if i % 2 == 0:
result.append(char.lower())
else:
result.append(char.upper())
i += 1
else:
result.append(char)
return ''.join(result)
s=input("Enter a string :")
print(Spongecase(s))