+ 2
Sequence with small & Large output like: tHe FoOl DoTh
How to make output which makes sequnce with small and LARGE letter in the sentence opposite to that i have in the example below? Thanks. def idiotic_str(input_str): ret = '' l = True for letter in input_str: if l: ret += letter.upper() else: ret += letter.lower() l = not l return ret print(idiotic_str(input('Please input string:'))) Thanks!
5 Respostas
+ 3
I don't know what you mean by opposite but the code does that because it changes value of "l" at each iteration that causes different behavior at each step. So if you change the initial value of "l" to False it returns a output that the lower and upper cases is opposite of what you will get from this code.
+ 2
https://code.sololearn.com/cWmCWR83ZyOu/?ref=app
+ 2
Thanks everybody!
Vitaly Sokol your code returning just capital letters =(
Oma Falk your code returning the same thing as mine, with first letter capital.
M3hran Thanks a lot! That works
+ 2
Hey Vitaly Sokol, thank you. It works as well, I just replaced i.lower() & i.upper() so it start with small letter.
def gen(i=1):
while 1 :
yield i; i = 0 if i else 1
print( (lambda st, g = gen():''.join([i.lower() if next(g) else i.upper() for i in st])) (input() or 'Printed a sequence of Large&small letters') )
Have a nice day!