+ 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!

28th Feb 2020, 8:26 PM
Stanislav Voloshchuk
Stanislav Voloshchuk - avatar
5 ответов
+ 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.
28th Feb 2020, 8:46 PM
M3hran
M3hran - avatar
28th Feb 2020, 9:05 PM
Vitaly Sokol
Vitaly Sokol - avatar
+ 2
https://code.sololearn.com/cWmCWR83ZyOu/?ref=app
28th Feb 2020, 9:09 PM
Oma Falk
Oma Falk - avatar
+ 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
28th Feb 2020, 9:27 PM
Stanislav Voloshchuk
Stanislav Voloshchuk - avatar
+ 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!
29th Feb 2020, 7:50 AM
Stanislav Voloshchuk
Stanislav Voloshchuk - avatar